Protect /checklist route

This commit is contained in:
Sam Becker 2023-09-06 18:27:55 -05:00
parent e7fb05d571
commit a8d4ae7288
2 changed files with 9 additions and 4 deletions

View File

@ -1,3 +1,4 @@
import { isRouteProtected } from '@/site/routes';
import NextAuth, { User, type DefaultSession } from 'next-auth';
import Credentials from 'next-auth/providers/credentials';
import { NextResponse } from 'next/server';
@ -39,16 +40,16 @@ export const {
const url = new URL(request.url);
const { pathname } = url;
const isUrlProtected = pathname.startsWith('/admin');
const isLoggedIn = !!auth?.user;
const isAuthorized = !isUrlProtected || isLoggedIn;
const isUrlProtected = isRouteProtected(pathname);
const isUserLoggedIn = !!auth?.user;
const isRequestAuthorized = !isUrlProtected || isUserLoggedIn;
if (pathname === '/admin') {
url.pathname = '/admin/photos';
return NextResponse.redirect(url);
}
return isAuthorized;
return isRequestAuthorized;
},
},
pages: {

View File

@ -21,3 +21,7 @@ export const isRoutePhotoShare = (pathname = '') =>
export const isRouteSignIn = (pathname = '') =>
pathname.startsWith('/sign-in');
export const isRouteProtected = (pathname = '') =>
pathname.startsWith('/admin') ||
pathname === '/checklist';