Avoid redirect loop: wait for auth to resolve before redirecting from Dashboard

cgen-4ecde8665964461e8ddcaaf052e7b577
This commit is contained in:
Builder.io 2025-09-27 20:45:10 +00:00
parent 7362145c0f
commit dfebb544cf

View file

@ -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();