Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions app/(home)/ambassador-dao/onboard/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,36 @@ const AmbasssadorDaoOnboardLayout = ({

useEffect(() => {
if (!isLoading && !user) {
router.push("/ambassador-dao");
// Check if the error is due to token acquisition failure
const tokenError = typeof window !== "undefined"
? localStorage.getItem("t1_token_error")
: null;

if (tokenError === "user_not_found") {
// User doesn't exist in Ambassador DAO - stay on onboard page to create profile
console.log("User not found in Ambassador DAO, staying on onboard page");
return;
} else if (tokenError === "server_error") {
// Server error - redirect to home to avoid loop
toast.error("Cannot connect to Ambassador DAO. Please try again later.");
return;
} else {
// Normal case: user not authenticated, redirect to main ambassador-dao page
router.push("/ambassador-dao");
}
}
}, [user, isLoading, router]);

if (isLoading) {
return <FullScreenLoader />;
}
return <main>{user && children}</main>;

// Allow rendering even without user if error is user_not_found (to show onboarding form)
const tokenError = typeof window !== "undefined"
? localStorage.getItem("t1_token_error")
: null;

return <main>{(user || tokenError === "user_not_found") && children}</main>;
};

export default AmbasssadorDaoOnboardLayout;
Loading