mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 07:51:13 -05:00
Fix: Synchronize user and profile state updates
This commit is contained in:
@@ -42,8 +42,8 @@ export function AuthButtons() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Show loading skeleton during auth check
|
// Show loading skeleton during auth check OR when user exists but profile hasn't loaded yet
|
||||||
if (loading) {
|
if (loading || (user && !profile)) {
|
||||||
return (
|
return (
|
||||||
<div className="flex gap-2 items-center">
|
<div className="flex gap-2 items-center">
|
||||||
<div className="h-8 w-16 bg-muted animate-pulse rounded" />
|
<div className="h-8 w-16 bg-muted animate-pulse rounded" />
|
||||||
|
|||||||
@@ -191,6 +191,8 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
|
|||||||
setSession(session);
|
setSession(session);
|
||||||
setUser(session.user);
|
setUser(session.user);
|
||||||
sessionVerifiedRef.current = true;
|
sessionVerifiedRef.current = true;
|
||||||
|
// Keep loading true until profile is fetched
|
||||||
|
setLoading(true);
|
||||||
} else if (event === 'INITIAL_SESSION') {
|
} else if (event === 'INITIAL_SESSION') {
|
||||||
if (session?.user) {
|
if (session?.user) {
|
||||||
authLog('[Auth] INITIAL_SESSION with user, setting session');
|
authLog('[Auth] INITIAL_SESSION with user, setting session');
|
||||||
@@ -296,10 +298,9 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
|
|||||||
|
|
||||||
profileFetchTimeoutRef.current = setTimeout(() => {
|
profileFetchTimeoutRef.current = setTimeout(() => {
|
||||||
fetchProfile(session.user.id, 0, () => {
|
fetchProfile(session.user.id, 0, () => {
|
||||||
if (shouldWaitForProfile) {
|
// Always set loading to false after profile fetch for authenticated users
|
||||||
authLog('[Auth] Profile fetch complete, setting loading to false');
|
authLog('[Auth] Profile fetch complete, setting loading to false');
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
profileFetchTimeoutRef.current = null;
|
profileFetchTimeoutRef.current = null;
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user