client: cleanup middleware redirect code

This commit is contained in:
Max Leiter 2022-04-06 14:42:18 -07:00
parent 5dabbbe64b
commit 18dff00a93
No known key found for this signature in database
GPG key ID: A3512F2F2F17EBDA

View file

@ -37,21 +37,16 @@ export function middleware(req: NextRequest, event: NextFetchEvent) {
return resp return resp
} }
} else if (isPageRequest) { } else if (isPageRequest) {
if (pathname === '/') {
if (signedIn) { if (signedIn) {
if (pathname === '/' || pathname === '/signin' || pathname === '/signup') {
return NextResponse.redirect(getURL('new')) return NextResponse.redirect(getURL('new'))
} }
// If you're not signed in we redirect the new post page to the home page } else if (!signedIn) {
} else if (pathname === '/new') { if (pathname === '/new') {
if (!signedIn) {
return NextResponse.redirect(getURL('signin')) 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() return NextResponse.next()