fix(react-auth): add updateUser to AuthContextValue + provider for local user state mutation

This commit is contained in:
saravanakumardb1 2026-02-28 11:38:27 -08:00
parent da165a589a
commit 1925370604
2 changed files with 13 additions and 0 deletions

View File

@ -274,6 +274,17 @@ export function createAuthProvider<TUser extends BaseUser = BaseUser>(config: Au
[api]
);
// ── Update user (local state + localStorage) ──
const updateUser = useCallback((updates: Partial<TUser>) => {
setUser(prev => {
if (!prev) return null;
const updated = { ...prev, ...updates };
localStorage.setItem(USER_KEY, JSON.stringify(updated));
return updated;
});
}, []);
// ── Delete account ─────────────────────────────
const deleteAccount = useCallback(
@ -319,6 +330,7 @@ export function createAuthProvider<TUser extends BaseUser = BaseUser>(config: Au
forgotPassword,
changePassword,
deleteAccount,
updateUser,
clearMessages,
}}
>

View File

@ -17,6 +17,7 @@ export interface AuthContextValue<TUser extends BaseUser = BaseUser> {
forgotPassword: (email: string) => Promise<boolean>;
changePassword: (currentPassword: string, newPassword: string) => Promise<boolean>;
deleteAccount: (password: string) => Promise<boolean>;
updateUser: (updates: Partial<TUser>) => void;
clearMessages: () => void;
}