fix(auth): clear stale localStorage session before OAuth to prevent 401
This commit is contained in:
@@ -25,6 +25,18 @@ export const useSocialAuth = () => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
setError(null);
|
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({
|
const { data, error: authError } = await supabase.auth.signInWithOAuth({
|
||||||
provider,
|
provider,
|
||||||
options: {
|
options: {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export const supabase = createClient<Database>(supabaseUrl, supabaseAnonKey, {
|
|||||||
autoRefreshToken: true,
|
autoRefreshToken: true,
|
||||||
persistSession: true,
|
persistSession: true,
|
||||||
detectSessionInUrl: true,
|
detectSessionInUrl: true,
|
||||||
flowType: 'implicit'
|
flowType: 'pkce'
|
||||||
},
|
},
|
||||||
realtime: {
|
realtime: {
|
||||||
params: {
|
params: {
|
||||||
|
|||||||
Reference in New Issue
Block a user