- Refresh wist de sessie alleen nog bij 400/401/403; 429/5xx/netwerkfout behoudt hem (opstart: rustig opnieuw proberen met backoff, anders gast zonder het cookie te raken) - Refresh is single-flight (opstart, 401-interceptor, profiel delen een lopende aanvraag) - GET-verzoeken met cache: no-store; gebruikerslijst: refetch bij focus en poll 45 s; sessie ververst als de eigen rol in de lijst afwijkt Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { useMutation } from '@tanstack/react-query';
|
|
import { api } from '@/lib/api-client';
|
|
import { useAuth } from '@/features/auth/context/auth-context';
|
|
import type { UserListItem } from '@/features/users/services/types';
|
|
|
|
export interface UpdateProfilePayload {
|
|
name: string;
|
|
email: string;
|
|
/** 'nl' | 'en'; '' clears the preference (site default); omitted leaves it unchanged. */
|
|
language?: string;
|
|
}
|
|
|
|
export interface ChangePasswordPayload {
|
|
currentPassword: string;
|
|
newPassword: string;
|
|
}
|
|
|
|
export function useUpdateProfile() {
|
|
const { refresh } = useAuth();
|
|
return useMutation<UserListItem, Error, UpdateProfilePayload>({
|
|
mutationFn: (data) => api.put<UserListItem>('/api/v1/Users/me', data),
|
|
onSuccess: () => {
|
|
// Sync AuthContext with updated name/email via token refresh
|
|
void refresh().catch(() => undefined); // a transient failure keeps the session as it is
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useChangePassword() {
|
|
return useMutation<void, Error, ChangePasswordPayload>({
|
|
mutationFn: (data) => api.post<void>('/api/v1/Auth/change-password', data),
|
|
});
|
|
}
|