correção login
This commit is contained in:
@@ -197,19 +197,21 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
|
||||
// Usa onAuthStateChange que dispara INITIAL_SESSION automaticamente
|
||||
// Evita duplicação com getSession() separado
|
||||
const { data: sub } = supabase.auth.onAuthStateChange(async (event, session) => {
|
||||
const { data: sub } = supabase.auth.onAuthStateChange((event, session) => {
|
||||
if (!mounted) return;
|
||||
|
||||
// Liberta o loading imediatamente ao primeiro evento de auth
|
||||
// para não bloquear a app enquanto os dados carregam
|
||||
setLoading(false);
|
||||
|
||||
if (session?.user) {
|
||||
await applyProfile(session.user.id, session.user.email);
|
||||
if (mounted) await refreshShops();
|
||||
applyProfile(session.user.id, session.user.email)
|
||||
.then(() => { if (mounted) refreshShops(); })
|
||||
.catch(console.error);
|
||||
} else {
|
||||
clearUser();
|
||||
if (mounted) await refreshShops();
|
||||
refreshShops().catch(console.error);
|
||||
}
|
||||
|
||||
// Liberta o loading após o primeiro evento
|
||||
if (mounted) setLoading(false);
|
||||
});
|
||||
|
||||
// Fallback: se o onAuthStateChange não disparar em 5s, liberta o loading
|
||||
|
||||
Reference in New Issue
Block a user