Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import { userApi } from '@/api/user.api' import type { User } from '@/types' // ---------------------------------------------------------------- // AUTH SERVICE (Keycloak Integration) // ---------------------------------------------------------------- export class AuthService { /** * Fetch current user from backend API * Backend validates Keycloak token and returns user info */ static async fetchMe(): Promise<User> { const { data: user } = await userApi.getMe() localStorage.setItem('user', JSON.stringify(user)) return user } /** * Get stored user from localStorage */ static getStoredUser(): User | null { const userStr = localStorage.getItem('user') if (!userStr) return null try { return JSON.parse(userStr) as User } catch { return null } } /** * Clear stored user data */ static clearStoredUser(): void { localStorage.removeItem('user') } } |