From 18dff00a931b36a4a85e8d73197101958ec08b06 Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Wed, 6 Apr 2022 14:42:18 -0700 Subject: [PATCH] client: cleanup middleware redirect code --- client/pages/_middleware.tsx | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/client/pages/_middleware.tsx b/client/pages/_middleware.tsx index b2d909f3..a3bba447 100644 --- a/client/pages/_middleware.tsx +++ b/client/pages/_middleware.tsx @@ -37,21 +37,16 @@ export function middleware(req: NextRequest, event: NextFetchEvent) { return resp } } else if (isPageRequest) { - if (pathname === '/') { - if (signedIn) { + if (signedIn) { + if (pathname === '/' || pathname === '/signin' || pathname === '/signup') { return NextResponse.redirect(getURL('new')) } - // If you're not signed in we redirect the new post page to the home page - } else if (pathname === '/new') { - if (!signedIn) { + } else if (!signedIn) { + if (pathname === '/new') { return NextResponse.redirect(getURL('signin')) } - // If you're signed in we redirect the sign in page to the home page (which is the new page) - } else if (pathname === '/signin' || pathname === '/signup') { - if (signedIn) { - return NextResponse.redirect(getURL('')) - } } + } return NextResponse.next()