From 1d5ba91af8c97d55e62b722bd380526dcf67c1a3 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Thu, 29 Feb 2024 00:39:25 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=B9=84=EC=9D=B8=EC=A6=9D=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=EB=A1=9C=20=EC=9D=B4=EB=8F=99=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20#223?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/withAuth.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/hooks/withAuth.tsx b/src/hooks/withAuth.tsx index 7c62c607..f5a8fc5b 100644 --- a/src/hooks/withAuth.tsx +++ b/src/hooks/withAuth.tsx @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { ComponentType } from 'react'; +import { ComponentType, useEffect } from 'react'; import { useRouter } from 'next/navigation'; @@ -15,10 +15,16 @@ function withAuth>( (prev, curr) => { return prev === curr; }, ); + useEffect(() => { + if (userId == null) { + router.push('/login'); + } + }, [userId, router]); + if (userId == null) { - router.push('/'); return null; } + return ; }; }