mirror of
https://gitea.gofwd.group/sean/gunbuilder-next-tailwind.git
synced 2025-12-06 02:56:45 -05:00
16 lines
513 B
TypeScript
16 lines
513 B
TypeScript
|
|
import { NextResponse, NextRequest } from 'next/server';
|
||
|
|
import { getToken } from 'next-auth/jwt';
|
||
|
|
|
||
|
|
export async function middleware(request: NextRequest) {
|
||
|
|
if (request.nextUrl.pathname.startsWith('/admin')) {
|
||
|
|
const token = await getToken({ req: request, secret: process.env.NEXTAUTH_SECRET });
|
||
|
|
if (!token || !token.isAdmin) {
|
||
|
|
return NextResponse.redirect(new URL('/account/login', request.url));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return NextResponse.next();
|
||
|
|
}
|
||
|
|
|
||
|
|
export const config = {
|
||
|
|
matcher: ['/admin/:path*'],
|
||
|
|
};
|