fix(auth): change flowType to implicit and optimise auth callback

This commit is contained in:
2026-02-22 14:54:17 -03:00
parent c1b1edef86
commit 96729793a8
2 changed files with 11 additions and 11 deletions

View File

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

View File

@@ -15,13 +15,6 @@ export const AuthCallback: React.FC = () => {
useEffect(() => { useEffect(() => {
console.log('🔄 AuthCallback montado.'); console.log('🔄 AuthCallback montado.');
// 1. Iniciar o timer de redirecionamento
const timer = setTimeout(() => {
console.log('⏰ Timeout disparado. Forçando ida para /');
window.location.href = '/';
}, 4000);
// 2. Processar sessão e garantir permissões do Super Admin
const processSession = async () => { const processSession = async () => {
try { try {
console.log('🔍 Verificando sessão em background...'); console.log('🔍 Verificando sessão em background...');
@@ -45,15 +38,22 @@ export const AuthCallback: React.FC = () => {
console.log('👑 Permissões de Super Admin aplicadas!'); console.log('👑 Permissões de Super Admin aplicadas!');
} }
// Redirecionar // Redirecionar imediatamente
window.location.href = '/'; window.location.replace('/');
} else {
// Sem sessão (ainda processando ou erro), esperar um pouco e tentar dnv ou ir para login
setTimeout(() => window.location.replace('/login'), 5000);
} }
} catch (e) { } catch (e) {
console.error('⚠️ Erro na verificação de sessão:', e); console.error('⚠️ Erro na verificação de sessão:', e);
window.location.replace('/login');
} }
}; };
processSession(); // Adiciona um pequeno delay para garantir que o supabase-js processou a URL (implicit / pkce hash)
const timer = setTimeout(() => {
processSession();
}, 800);
return () => clearTimeout(timer); return () => clearTimeout(timer);
}, [navigate]); }, [navigate]);