39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
'use client';
|
|
|
|
import { useEffect } from 'react';
|
|
import { useAuth } from '@/lib/auth';
|
|
|
|
export default function Home() {
|
|
const { user, isLoading } = useAuth();
|
|
|
|
// Add debug logs
|
|
console.log('Root page state:', { isLoading, userAuthenticated: !!user });
|
|
|
|
useEffect(() => {
|
|
if (!isLoading) {
|
|
console.log('Preparing to redirect from root page', { isLoggedIn: !!user });
|
|
|
|
// Use hard redirect to ensure full page refresh
|
|
if (user) {
|
|
console.log('User is logged in, redirecting to analytics page');
|
|
window.location.href = '/analytics';
|
|
} else {
|
|
console.log('User is not logged in, redirecting to login page');
|
|
window.location.href = '/login';
|
|
}
|
|
}
|
|
}, [isLoading, user]);
|
|
|
|
// Display loading indicator with status information
|
|
return (
|
|
<div className="flex items-center justify-center min-h-screen">
|
|
<div className="text-center">
|
|
<div className="animate-spin rounded-full h-16 w-16 border-t-2 border-b-2 border-blue-500 mx-auto"></div>
|
|
<p className="mt-4 text-lg text-gray-700">Loading...</p>
|
|
<p className="mt-2 text-sm text-gray-500">
|
|
Status: {isLoading ? 'Checking login status' : (user ? 'Logged in' : 'Not logged in')}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
);
|
|
} |