From 61165c88c41275b265b767ec924cf68beba4fca7 Mon Sep 17 00:00:00 2001 From: web Date: Thu, 24 Jul 2025 10:10:31 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(auth):=20Implement=20user=20?= =?UTF-8?q?redirection=20to=20dashboard=20upon=20authentication?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/admin/app/(auth)/page.tsx | 11 ++++++++++- apps/user/app/(main)/page.tsx | 23 ++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) 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 (