Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
1.0 kB · 33 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233const STORAGE_KEYS = { CURRENT_PLAYER_ID: 'current-player-id', CURRENT_GAME_ID: 'current-game-id'} as const;
export interface SessionData { playerId: string | null; gameId: string | null;}
export const sessionStorage = { setPlayerSession(playerId: string, gameId: string): void { window.sessionStorage.setItem(STORAGE_KEYS.CURRENT_PLAYER_ID, playerId); window.sessionStorage.setItem(STORAGE_KEYS.CURRENT_GAME_ID, gameId); },
getPlayerSession(): SessionData { const playerId = window.sessionStorage.getItem(STORAGE_KEYS.CURRENT_PLAYER_ID); const gameId = window.sessionStorage.getItem(STORAGE_KEYS.CURRENT_GAME_ID); return { playerId, gameId }; },
clearPlayerSession(): void { window.sessionStorage.removeItem(STORAGE_KEYS.CURRENT_PLAYER_ID); window.sessionStorage.removeItem(STORAGE_KEYS.CURRENT_GAME_ID); },
hasPlayerSession(): boolean { const { playerId, gameId } = this.getPlayerSession(); return !!(playerId && gameId); }};