🐛 fix(auth): Implement user redirection to dashboard upon authentication
This commit is contained in:
parent
6e62353096
commit
61165c88c4
@ -8,13 +8,22 @@ import LoginLottie from '@workspace/ui/lotties/login.json';
|
|||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import Image from 'next/legacy/image';
|
import Image from 'next/legacy/image';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { useEffect } from 'react';
|
||||||
import EmailAuthForm from './email/auth-form';
|
import EmailAuthForm from './email/auth-form';
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
const t = useTranslations('auth');
|
const t = useTranslations('auth');
|
||||||
const { common } = useGlobalStore();
|
const { common, user } = useGlobalStore();
|
||||||
const { site } = common;
|
const { site } = common;
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
useEffect(() => {
|
||||||
|
if (user) {
|
||||||
|
router.replace('/dashboard');
|
||||||
|
}
|
||||||
|
}, [router, user]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className='bg-muted/50 flex h-full min-h-screen items-center'>
|
<main className='bg-muted/50 flex h-full min-h-screen items-center'>
|
||||||
<div className='flex size-full flex-auto flex-col justify-center lg:flex-row'>
|
<div className='flex size-full flex-auto flex-col justify-center lg:flex-row'>
|
||||||
|
|||||||
@ -2,8 +2,29 @@ import { GlobalMap } from '@/components/main/global-map';
|
|||||||
import { Hero } from '@/components/main/hero';
|
import { Hero } from '@/components/main/hero';
|
||||||
import { ProductShowcase } from '@/components/main/product-showcase/index';
|
import { ProductShowcase } from '@/components/main/product-showcase/index';
|
||||||
import { Stats } from '@/components/main/stats';
|
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 (
|
return (
|
||||||
<main className='container space-y-16'>
|
<main className='container space-y-16'>
|
||||||
<Hero />
|
<Hero />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user