import type { AuthConfig } from "../../shared/auth-config"; import type { AuthStateValue } from "../../shared/auth-messages"; export function createLoggedOutAuthState( config?: Pick, lastError?: string | null ): AuthStateValue { return { isAuthenticated: false, lastError: lastError ?? null, resource: config?.apiResource ?? null }; } export function createLoggedInAuthState( claims: Record | null | undefined, config?: Pick ): AuthStateValue { return { accessTokenExpiresAt: null, isAuthenticated: true, resource: config?.apiResource ?? null, scopes: config?.scopes ?? [], tokenAvailable: true, userInfo: { email: readStringClaim(claims, "email"), name: readStringClaim(claims, "name"), sub: readStringClaim(claims, "sub"), username: readStringClaim(claims, "username") } }; } function readStringClaim( claims: Record | null | undefined, key: string ): string | undefined { const value = claims?.[key]; return typeof value === "string" ? value : undefined; }