This commit is contained in:
IGNY8 VPS (Salman)
2025-12-08 18:22:10 +00:00
parent 33ad6768ec
commit 9f85ce4f52
11 changed files with 774 additions and 198 deletions

View File

@@ -39,15 +39,26 @@ export default function ProtectedRoute({ children }: ProtectedRouteProps) {
// Validate account + plan whenever auth/user changes
useEffect(() => {
console.log('[ProtectedRoute] Auth state changed:', {
isAuthenticated,
hasUser: !!user,
hasAccount: !!user?.account,
pathname: location.pathname
});
if (!isAuthenticated) {
console.log('[ProtectedRoute] Not authenticated, will redirect to signin');
return;
}
if (!user?.account) {
console.error('[ProtectedRoute] User has no account, logging out');
setErrorMessage('This user is not linked to an account. Please contact support.');
logout();
return;
}
console.log('[ProtectedRoute] Auth validation passed');
}, [isAuthenticated, user, logout]);
// Immediate check on mount: if loading is true, reset it immediately
@@ -114,6 +125,7 @@ export default function ProtectedRoute({ children }: ProtectedRouteProps) {
// Redirect to signin if not authenticated
if (!isAuthenticated) {
console.log('[ProtectedRoute] Redirecting to /signin - not authenticated');
return <Navigate to="/signin" state={{ from: location }} replace />;
}