39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
'use client';
|
|
|
|
import { useEffect } from 'react';
|
|
import { useAuth } from '@/lib/auth';
|
|
|
|
export default function Home() {
|
|
const { user, isLoading } = useAuth();
|
|
|
|
// 添加调试日志
|
|
console.log('根页面状态:', { isLoading, userAuthenticated: !!user });
|
|
|
|
useEffect(() => {
|
|
if (!isLoading) {
|
|
console.log('准备从根页面重定向', { isLoggedIn: !!user });
|
|
|
|
// 使用硬重定向确保页面完全刷新
|
|
if (user) {
|
|
console.log('用户已登录,重定向到分析页面');
|
|
window.location.href = '/analytics';
|
|
} else {
|
|
console.log('用户未登录,重定向到登录页面');
|
|
window.location.href = '/login';
|
|
}
|
|
}
|
|
}, [isLoading, user]);
|
|
|
|
// 显示加载指示器,并包含状态信息
|
|
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">正在加载...</p>
|
|
<p className="mt-2 text-sm text-gray-500">
|
|
状态: {isLoading ? '检查登录中' : (user ? '已登录' : '未登录')}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
);
|
|
} |