add website tests
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { Loader2 } from 'lucide-react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import OnboardingWizard from '@/components/onboarding/OnboardingWizard';
|
||||
import { useCurrentDriver } from '@/hooks/useDriverService';
|
||||
@@ -12,13 +13,23 @@ export default function OnboardingPage() {
|
||||
const { session } = useAuth();
|
||||
const { data: driver, isLoading } = useCurrentDriver();
|
||||
|
||||
// If user is not authenticated, redirect to login
|
||||
if (!session) {
|
||||
router.replace('/auth/login?returnTo=/onboarding');
|
||||
const shouldRedirectToLogin = !session;
|
||||
const shouldRedirectToDashboard = !isLoading && Boolean(driver);
|
||||
|
||||
useEffect(() => {
|
||||
if (shouldRedirectToLogin) {
|
||||
router.replace('/auth/login?returnTo=/onboarding');
|
||||
return;
|
||||
}
|
||||
if (shouldRedirectToDashboard) {
|
||||
router.replace('/dashboard');
|
||||
}
|
||||
}, [router, shouldRedirectToLogin, shouldRedirectToDashboard]);
|
||||
|
||||
if (shouldRedirectToLogin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Show loading while checking driver data
|
||||
if (isLoading) {
|
||||
return (
|
||||
<main className="min-h-screen bg-deep-graphite flex items-center justify-center">
|
||||
@@ -27,9 +38,7 @@ export default function OnboardingPage() {
|
||||
);
|
||||
}
|
||||
|
||||
// If driver profile exists, onboarding is complete – go to dashboard
|
||||
if (driver) {
|
||||
router.replace('/dashboard');
|
||||
if (shouldRedirectToDashboard) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user