Avoid redirect loop: wait for auth to resolve before redirecting from Dashboard
cgen-4ecde8665964461e8ddcaaf052e7b577
This commit is contained in:
parent
7362145c0f
commit
dfebb544cf
1 changed files with 9 additions and 3 deletions
|
|
@ -57,14 +57,20 @@ export default function Dashboard() {
|
|||
useEffect(() => {
|
||||
console.log("Dashboard useEffect:", { user: !!user, profile: !!profile, authLoading });
|
||||
|
||||
// Force redirect immediately if no user
|
||||
if (!user) {
|
||||
console.log("No user, redirecting to login");
|
||||
// Only redirect to login when auth is resolved and there's no user
|
||||
if (!user && !authLoading) {
|
||||
console.log("No user after auth resolved, redirecting to login");
|
||||
setIsLoading(false);
|
||||
navigate("/login", { replace: true });
|
||||
return;
|
||||
}
|
||||
|
||||
// While auth is still resolving, keep showing loading state
|
||||
if (!user && authLoading) {
|
||||
setIsLoading(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (user && profile) {
|
||||
console.log("User and profile exist, loading dashboard data");
|
||||
loadDashboardData();
|
||||
|
|
|
|||
Loading…
Reference in a new issue