sadasd
This commit is contained in:
@@ -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 />;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user