From c60e0d22b6d614edd478cb033a386dfbd6c99b62 Mon Sep 17 00:00:00 2001 From: Yutaro Kijima Date: Tue, 12 Dec 2023 15:29:57 +0900 Subject: [PATCH] set redirect from index page --- src/app/dashboard/page.tsx | 1 + src/app/page.tsx | 67 +++++--------------------------------- 2 files changed, 9 insertions(+), 59 deletions(-) diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index cdd48c9..2e27f9e 100755 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -14,6 +14,7 @@ const DashboardPage = async () => { const { data: auth } = await supabase.auth.getUser(token.value); if (!auth.user) { + cookie.delete('token'); redirect('/auth/sign-in'); } const { data: user } = await supabase diff --git a/src/app/page.tsx b/src/app/page.tsx index 1f62962..8963143 100755 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,64 +1,13 @@ -import Image from 'next/image'; - -import styles from './page.module.css'; +import { cookies } from 'next/headers'; +import { redirect } from 'next/navigation'; export default function Home() { - return ( -
-
- Next.js Logo -
-
- -

- Register-> -

-
- -

- Sign In -> -

-
+ const cookie = cookies(); + const token = cookie.get('token'); - -

- Dashboard -> -

-
+ if (token) { + redirect('/dashboard'); + } - -

- Github-> -

-
-
-
- ); + redirect('/auth/sign-in'); }