Protect /checklist route
This commit is contained in:
parent
e7fb05d571
commit
a8d4ae7288
@ -1,3 +1,4 @@
|
|||||||
|
import { isRouteProtected } from '@/site/routes';
|
||||||
import NextAuth, { User, type DefaultSession } from 'next-auth';
|
import NextAuth, { User, type DefaultSession } from 'next-auth';
|
||||||
import Credentials from 'next-auth/providers/credentials';
|
import Credentials from 'next-auth/providers/credentials';
|
||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
@ -39,16 +40,16 @@ export const {
|
|||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
const { pathname } = url;
|
const { pathname } = url;
|
||||||
|
|
||||||
const isUrlProtected = pathname.startsWith('/admin');
|
const isUrlProtected = isRouteProtected(pathname);
|
||||||
const isLoggedIn = !!auth?.user;
|
const isUserLoggedIn = !!auth?.user;
|
||||||
const isAuthorized = !isUrlProtected || isLoggedIn;
|
const isRequestAuthorized = !isUrlProtected || isUserLoggedIn;
|
||||||
|
|
||||||
if (pathname === '/admin') {
|
if (pathname === '/admin') {
|
||||||
url.pathname = '/admin/photos';
|
url.pathname = '/admin/photos';
|
||||||
return NextResponse.redirect(url);
|
return NextResponse.redirect(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
return isAuthorized;
|
return isRequestAuthorized;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
pages: {
|
pages: {
|
||||||
|
|||||||
@ -21,3 +21,7 @@ export const isRoutePhotoShare = (pathname = '') =>
|
|||||||
|
|
||||||
export const isRouteSignIn = (pathname = '') =>
|
export const isRouteSignIn = (pathname = '') =>
|
||||||
pathname.startsWith('/sign-in');
|
pathname.startsWith('/sign-in');
|
||||||
|
|
||||||
|
export const isRouteProtected = (pathname = '') =>
|
||||||
|
pathname.startsWith('/admin') ||
|
||||||
|
pathname === '/checklist';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user