mirror of
https://github.com/luxfi/mpc.git
synced 2026-09-24 00:26:24 +00:00
- layout.tsx: fix font loading — use Geist Sans/Mono from geist package matching tailwind.config.ts CSS variable names (was loading Inter) - login/page.tsx: replace email/password form with "Continue with Lux ID" button that redirects to lux.id OIDC authorization endpoint - auth/callback/page.tsx: new OIDC callback page — validates state param, exchanges authorization code for tokens at lux.id/oauth/token, stores JWT in localStorage, redirects to / - middleware.ts: Next.js edge middleware that checks lux_mpc_session cookie and redirects unauthenticated requests to /login before page renders - lib/auth.ts: set lux_mpc_session cookie on setTokens() so middleware can detect auth state; clear it on clearTokens() (logout) - k8s/dashboard-deployment.yaml: add NEXT_PUBLIC_IAM_URL and NEXT_PUBLIC_IAM_CLIENT_ID env vars for lux.id OIDC integration
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
// JWT token management via localStorage
|
|
|
|
const ACCESS_TOKEN_KEY = 'lux_mpc_access_token'
|
|
const REFRESH_TOKEN_KEY = 'lux_mpc_refresh_token'
|
|
const USER_EMAIL_KEY = 'lux_mpc_user_email'
|
|
|
|
export function getToken(): string | null {
|
|
if (typeof window === 'undefined') return null
|
|
return localStorage.getItem(ACCESS_TOKEN_KEY)
|
|
}
|
|
|
|
export function getRefreshToken(): string | null {
|
|
if (typeof window === 'undefined') return null
|
|
return localStorage.getItem(REFRESH_TOKEN_KEY)
|
|
}
|
|
|
|
export function setTokens(accessToken: string, refreshToken: string): void {
|
|
if (typeof window === 'undefined') return
|
|
localStorage.setItem(ACCESS_TOKEN_KEY, accessToken)
|
|
localStorage.setItem(REFRESH_TOKEN_KEY, refreshToken)
|
|
// Set session cookie so Next.js middleware can enforce auth on server side
|
|
document.cookie = 'lux_mpc_session=1; path=/; SameSite=Strict; Secure'
|
|
}
|
|
|
|
export function setUserEmail(email: string): void {
|
|
if (typeof window === 'undefined') return
|
|
localStorage.setItem(USER_EMAIL_KEY, email)
|
|
}
|
|
|
|
export function getUserEmail(): string | null {
|
|
if (typeof window === 'undefined') return null
|
|
return localStorage.getItem(USER_EMAIL_KEY)
|
|
}
|
|
|
|
export function clearTokens(): void {
|
|
if (typeof window === 'undefined') return
|
|
localStorage.removeItem(ACCESS_TOKEN_KEY)
|
|
localStorage.removeItem(REFRESH_TOKEN_KEY)
|
|
localStorage.removeItem(USER_EMAIL_KEY)
|
|
// Clear session cookie so middleware redirects to /login immediately
|
|
document.cookie = 'lux_mpc_session=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Strict'
|
|
}
|
|
|
|
export function isAuthenticated(): boolean {
|
|
return getToken() !== null
|
|
}
|