diff --git a/apps/admin/app/(auth)/page.tsx b/apps/admin/app/(auth)/page.tsx index 945d55f..b0d6b5c 100644 --- a/apps/admin/app/(auth)/page.tsx +++ b/apps/admin/app/(auth)/page.tsx @@ -8,13 +8,22 @@ import LoginLottie from '@workspace/ui/lotties/login.json'; import { useTranslations } from 'next-intl'; import Image from 'next/legacy/image'; import Link from 'next/link'; +import { useRouter } from 'next/navigation'; +import { useEffect } from 'react'; import EmailAuthForm from './email/auth-form'; export default function Page() { const t = useTranslations('auth'); - const { common } = useGlobalStore(); + const { common, user } = useGlobalStore(); const { site } = common; + const router = useRouter(); + useEffect(() => { + if (user) { + router.replace('/dashboard'); + } + }, [router, user]); + return (
diff --git a/apps/user/app/(main)/page.tsx b/apps/user/app/(main)/page.tsx index 3d540bb..ea4bbf4 100644 --- a/apps/user/app/(main)/page.tsx +++ b/apps/user/app/(main)/page.tsx @@ -2,8 +2,29 @@ import { GlobalMap } from '@/components/main/global-map'; import { Hero } from '@/components/main/hero'; import { ProductShowcase } from '@/components/main/product-showcase/index'; import { Stats } from '@/components/main/stats'; +import { queryUserInfo } from '@/services/user/user'; +import { cookies } from 'next/headers'; +import { redirect } from 'next/navigation'; + +export default async function Home() { + const Authorization = (await cookies()).get('Authorization')?.value; + + if (Authorization) { + let user = null; + try { + user = await queryUserInfo({ + skipErrorHandler: true, + Authorization, + }).then((res) => res.data.data); + } catch (error) { + console.log('Token validation failed:', error); + } + + if (user) { + redirect('/dashboard'); + } + } -export default function Home() { return (