Add timeout to prevent infinite loading in AuthContext
cgen-7304cc13c3ae495c975e04fda449cf3b
This commit is contained in:
parent
03ca1fa22f
commit
cce06096d8
1 changed files with 10 additions and 1 deletions
|
|
@ -44,18 +44,27 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
// Add timeout to ensure loading doesn't get stuck
|
||||
const loadingTimeout = setTimeout(() => {
|
||||
console.log("Auth loading timeout - forcing loading to false");
|
||||
setLoading(false);
|
||||
}, 5000);
|
||||
|
||||
// Get initial session
|
||||
supabase.auth
|
||||
.getSession()
|
||||
.then(({ data: { session } }) => {
|
||||
clearTimeout(loadingTimeout);
|
||||
setSession(session);
|
||||
setUser(session?.user ?? null);
|
||||
if (session?.user) {
|
||||
fetchUserProfile(session.user.id);
|
||||
} else {
|
||||
setLoading(false);
|
||||
}
|
||||
setLoading(false);
|
||||
})
|
||||
.catch((error) => {
|
||||
clearTimeout(loadingTimeout);
|
||||
console.error("Error getting session:", error);
|
||||
setLoading(false);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue