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(() => {
|
useEffect(() => {
|
||||||
console.log("Dashboard useEffect:", { user: !!user, profile: !!profile, authLoading });
|
console.log("Dashboard useEffect:", { user: !!user, profile: !!profile, authLoading });
|
||||||
|
|
||||||
// Force redirect immediately if no user
|
// Only redirect to login when auth is resolved and there's no user
|
||||||
if (!user) {
|
if (!user && !authLoading) {
|
||||||
console.log("No user, redirecting to login");
|
console.log("No user after auth resolved, redirecting to login");
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
navigate("/login", { replace: true });
|
navigate("/login", { replace: true });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// While auth is still resolving, keep showing loading state
|
||||||
|
if (!user && authLoading) {
|
||||||
|
setIsLoading(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (user && profile) {
|
if (user && profile) {
|
||||||
console.log("User and profile exist, loading dashboard data");
|
console.log("User and profile exist, loading dashboard data");
|
||||||
loadDashboardData();
|
loadDashboardData();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue