fix: user reset

This commit is contained in:
Vukasin 2025-07-24 17:49:32 +02:00
parent f702b0ddf2
commit 64b12fb719
1 changed files with 7 additions and 1 deletions

View File

@ -43,7 +43,13 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
const { data: authListener } = supabase.auth.onAuthStateChange(
async (event, newSession) => {
setSession(newSession);
setUser(newSession?.user ?? null);
// Only update user state on actual auth events, not token refresh
if (event === 'SIGNED_IN' || event === 'SIGNED_OUT') {
setUser(newSession?.user ?? null);
}
// For TOKEN_REFRESHED events, keep the existing user state
if (isLoading) setIsLoading(false);
if (event === 'SIGNED_IN' && newSession?.user) {
await checkAndInstallSunaAgent(newSession.user.id, newSession.user.created_at);