Enhance authentication flow by implementing ProtectedRoute component across various pages, ensuring users are redirected based on their authentication status. Update login page to support Google sign-in and handle redirect URLs after login. Modify analytics and links pages to include loading indicators and protected access. Update next.config.ts to enable middleware for edge functions.

This commit is contained in:
2025-04-23 17:36:54 +08:00
parent c56410b4de
commit 1b4e0bafc7
15 changed files with 597 additions and 85 deletions

View File

@@ -1,5 +1,32 @@
import { redirect } from 'next/navigation';
'use client';
import { useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { useAuth } from '@/lib/auth';
export default function Home() {
redirect('/analytics');
const router = useRouter();
const { user, isLoading } = useAuth();
useEffect(() => {
if (!isLoading) {
if (user) {
// 已登录用户重定向到分析页面
router.push('/analytics');
} else {
// 未登录用户重定向到登录页面
router.push('/login');
}
}
}, [user, isLoading, router]);
// 显示加载指示器
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>
</div>
</div>
);
}