Skip to content
Merged
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
8 changes: 8 additions & 0 deletions src/components/lifecycle-guard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ export function LifecycleGuard({ children }: LifecycleGuardProps) {
return;
}

// Guard: If loaded and not authenticated, always redirect to sign-in
if (!lifecycleState.isAuthenticated) {
const returnUrl = encodeURIComponent(pathname);
redirectingRef.current = true;
router.push(`/sign-in?returnUrl=${returnUrl}`);
return;
}

// 1. Force Redirect (Server Authority)
// If server explicitly says "Go here" AND we aren't already there.
// EXCEPTION: Allow access to any path in allowedPaths even if redirectTo is set.
Expand Down
12 changes: 10 additions & 2 deletions src/features/auth/api/use-account-lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,22 @@ export const useGetAccountLifecycle = () => {
const response = await client.api.auth.lifecycle.$get();

if (!response.ok) {
// If unauthorized, return unauthenticated state
// If unauthorized/session invalid, redirect to sign-in
return {
data: {
...INITIAL_LIFECYCLE_STATE,
isLoaded: true,
isLoading: false,
},
lifecycle: INITIAL_ROUTING,
lifecycle: {
state: "UNAUTHENTICATED",
redirectTo: "/sign-in",
allowedPaths: [],
blockedPaths: ["*"],
isTrialExpired: false,
trialCreditGranted: false,
trialCreditExpiresAt: null,
},
};
}

Expand Down
Loading