mancala/apps/frontend/src/context/context.tsx
Halit Aksoy f5dcf930fa feat(frontend): log in with Keycloak, as a guest or with an account
- First visit logs in as a new guest through Keycloak without a form;
  the session, including an offline refresh token, is kept in local storage
- Account menu on the home page: guests can log in or sign up, users can
  log out (which starts a new guest session)
- The WebSocket client in core authenticates with the access token after
  connecting, reports "connected" once the server accepts it, and re-sends
  renewed tokens on the open connection
- Game page shows player names; guests appear as "Guest 4F2A"
- Auth channels, AuthUser and player names in UserConnectionInfo move to
  core and the backend uses them from there
- Mobile keeps using userKey login for now
2026-10-14 02:22:13 +03:00

32 lines
1012 B
TypeScript

import { keycloak, server } from "../const/config";
import { RTMT, RTMTWS, ThemeManager } from "@mancala/core";
import { HttpServiceImpl } from "../service/HttpService";
import { GameStore, GameStoreImpl } from "../store/GameStore";
import { AuthService } from "../auth/AuthService";
import { LocalStorage } from "../storage";
import { Storage } from '@mancala/core'
export type Context = {
rtmt: RTMT;
authService: AuthService;
themeManager: ThemeManager;
gameStore: GameStore;
storage: Storage;
};
export const initContext = (): Context => {
const rtmt = new RTMTWS();
const httpService = new HttpServiceImpl(server.serverAdress);
const authService = new AuthService({ keycloakUrl: keycloak.url, realm: keycloak.realm, clientId: keycloak.clientId });
const gameStore = new GameStoreImpl({ httpService });
const storage = new LocalStorage();
const themeManager = new ThemeManager(storage);
return {
rtmt: rtmt,
authService,
themeManager,
gameStore,
storage
};
};