fix(react-auth): add updateUser to AuthContextValue + provider for local user state mutation
This commit is contained in:
parent
da165a589a
commit
1925370604
@ -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,
|
||||
}}
|
||||
>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user