U2 identity-mail-flows (frontend en documentatie): taalkeuze, mailresultaat, opnieuw mailen
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
||||
import type { AuthResponse } from '@/features/auth/services/types';
|
||||
import { api } from '@/lib/api-client';
|
||||
import { changeLanguage } from '@/i18n/config';
|
||||
import { AuthContext, type AuthContextValue, type AuthStatus } from '@/features/auth/context/auth-context';
|
||||
|
||||
/** The user's own language choice wins over the browser default; no preference leaves things alone. */
|
||||
function applyPreferredLanguage(language: 'nl' | 'en' | null | undefined) {
|
||||
if (language === 'nl' || language === 'en') void changeLanguage(language);
|
||||
}
|
||||
|
||||
/**
|
||||
* Owns the in-memory authentication session. On mount it attempts a silent
|
||||
* refresh using the httpOnly cookie (BR-U1-01) and wires the ApiClient's
|
||||
@@ -14,7 +20,15 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
const [expiresAt, setExpiresAt] = useState<string | null>(null);
|
||||
const [status, setStatus] = useState<AuthStatus>('loading');
|
||||
|
||||
// The user's saved language is applied once per sign-in (the first session after the page loads and
|
||||
// after each login), not on every later token refresh, so a temporary switch in the top bar survives.
|
||||
const applyLanguageNext = useRef(true);
|
||||
|
||||
const applySession = useCallback((data: AuthResponse) => {
|
||||
if (applyLanguageNext.current) {
|
||||
applyLanguageNext.current = false;
|
||||
applyPreferredLanguage(data.user.language);
|
||||
}
|
||||
setUser(data.user);
|
||||
setAccessToken(data.accessToken);
|
||||
setExpiresAt(data.expiresAt);
|
||||
@@ -50,6 +64,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
{ email, password },
|
||||
{ skipAuthRefresh: true },
|
||||
);
|
||||
applyLanguageNext.current = true;
|
||||
applySession(data);
|
||||
},
|
||||
[applySession],
|
||||
|
||||
@@ -7,6 +7,8 @@ export interface User {
|
||||
name: string;
|
||||
role: UserRole;
|
||||
isActive: boolean;
|
||||
/** Preferred language (also for e-mails); absent or null = the site default. */
|
||||
language?: 'nl' | 'en' | null;
|
||||
}
|
||||
|
||||
export interface AuthResponse {
|
||||
|
||||
Reference in New Issue
Block a user