fix(auth): clear stale localStorage session before OAuth to prevent 401

This commit is contained in:
2026-02-22 15:36:51 -03:00
parent 15bed40f16
commit 2b117e399c
2 changed files with 13 additions and 1 deletions

View File

@@ -25,6 +25,18 @@ export const useSocialAuth = () => {
setLoading(true);
setError(null);
// CRÍTICO: Limpar qualquer sessão antiga do localStorage antes de iniciar o OAuth.
// Sem isso, o Supabase SDK tenta validar o token antigo na página de callback
// e retorna 401 (GET /auth/v1/user) antes mesmo do nosso código rodar.
await supabase.auth.signOut({ scope: 'local' });
// Limpar manualmente chaves residuais que possam conflitar
Object.keys(localStorage).forEach(key => {
if (key.startsWith('sb-') && key.includes(window.location.hostname === 'localhost' ? 'localhost' : 'xzudfhifaancyxxfdejx')) {
localStorage.removeItem(key);
}
});
const { data, error: authError } = await supabase.auth.signInWithOAuth({
provider,
options: {

View File

@@ -16,7 +16,7 @@ export const supabase = createClient<Database>(supabaseUrl, supabaseAnonKey, {
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: true,
flowType: 'implicit'
flowType: 'pkce'
},
realtime: {
params: {