From 0f60da0d3664354edb7bd0eec391b57da453b89b Mon Sep 17 00:00:00 2001 From: SeonghunYang Date: Thu, 25 Apr 2024 11:29:23 +0000 Subject: [PATCH 01/39] [web] feat: Update middleware.ts to improve guest path handling --- middleware.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/middleware.ts b/middleware.ts index c61ab09a..b701287e 100644 --- a/middleware.ts +++ b/middleware.ts @@ -31,10 +31,12 @@ async function getAuth(request: NextRequest): Promise<{ }; } -const allowdGuestPath = ['/tutorial', '/sign-in', '/sign-up', '/find-password', '/find-id']; +const allowdOnlyGuestPath = ['/sign-in', '/sign-up', '/find-password', '/find-id']; +const allowdGuestPath = ['/', '/tutorial', ...allowdOnlyGuestPath]; -function isAllowedGuestPath(path: string) { - return allowdGuestPath.some((allowedPath) => path.startsWith(allowedPath)); +function isAllowedGuestPath(path: string, strict: boolean = false) { + const allowdPath = strict ? allowdOnlyGuestPath : allowdGuestPath; + return allowdPath.some((allowedPath) => path.startsWith(allowedPath)); } export async function middleware(request: NextRequest) { @@ -51,6 +53,10 @@ export async function middleware(request: NextRequest) { if (auth.role === 'guest' && !isAllowedGuestPath(request.nextUrl.pathname)) { return Response.redirect(new URL('/sign-in', request.url)); } + + if (auth.role !== 'guest' && isAllowedGuestPath(request.nextUrl.pathname, true)) { + return Response.redirect(new URL('/my', request.url)); + } } } From ae407937ac5dd0818ca0cb89729125c98100af8f Mon Sep 17 00:00:00 2001 From: SeonghunYang Date: Thu, 25 Apr 2024 11:36:58 +0000 Subject: [PATCH 02/39] feat: Add signOut function and redirect to sign-in page --- app/business/user/user.command.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/business/user/user.command.ts b/app/business/user/user.command.ts index 33a1f833..a4f45fb8 100644 --- a/app/business/user/user.command.ts +++ b/app/business/user/user.command.ts @@ -15,6 +15,13 @@ import { cookies } from 'next/headers'; import { isValidation } from '@/app/utils/zod/validation.util'; import { redirect } from 'next/navigation'; +export async function signOut() { + cookies().delete('accessToken'); + cookies().delete('refreshToken'); + + redirect('/sign-in'); +} + export async function validateToken(): Promise { const accessToken = cookies().get('accessToken')?.value; const refreshToken = cookies().get('refreshToken')?.value; From 944399f76618fb928f31b97f340f7d4296a76398 Mon Sep 17 00:00:00 2001 From: SeonghunYang Date: Thu, 25 Apr 2024 11:38:16 +0000 Subject: [PATCH 03/39] feat: Add SignOutButton component to UserInfoNavigator --- app/ui/user/user-info-navigator/sign-out-button.tsx | 11 +++++++++++ .../user/user-info-navigator/user-info-navigator.tsx | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 app/ui/user/user-info-navigator/sign-out-button.tsx diff --git a/app/ui/user/user-info-navigator/sign-out-button.tsx b/app/ui/user/user-info-navigator/sign-out-button.tsx new file mode 100644 index 00000000..3fbe6726 --- /dev/null +++ b/app/ui/user/user-info-navigator/sign-out-button.tsx @@ -0,0 +1,11 @@ +'use client'; +import { signOut } from '@/app/business/user/user.command'; +import Button from '../../view/atom/button/button'; + +export default function SignOutButton() { + const handleSignOut = async () => { + await signOut(); + }; + + return