Merge pull request #1061 from kubet/fix/refresh-token-timing

fix: user reset
This commit is contained in:
kubet 2025-07-24 17:50:13 +02:00 committed by GitHub
commit 06e10831fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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( const { data: authListener } = supabase.auth.onAuthStateChange(
async (event, newSession) => { async (event, newSession) => {
setSession(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 (isLoading) setIsLoading(false);
if (event === 'SIGNED_IN' && newSession?.user) { if (event === 'SIGNED_IN' && newSession?.user) {
await checkAndInstallSunaAgent(newSession.user.id, newSession.user.created_at); await checkAndInstallSunaAgent(newSession.user.id, newSession.user.created_at);