finally building
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import { auth } from '@workspace/auth';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { auth } from '@/auth';
|
||||
import { NextResponse, NextRequest } from 'next/server';
|
||||
|
||||
export default auth((req: any) => {
|
||||
// If the user is unauthenticated or an admin, allow the request.
|
||||
if (!req.auth || req.auth.user?.role === 'ADMIN') {
|
||||
export default auth((req: NextRequest) => {
|
||||
if (!req.auth) {
|
||||
return NextResponse.redirect(new URL('/login', req.url));
|
||||
}
|
||||
|
||||
if (req.auth.user?.role === 'ADMIN') {
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
@@ -11,8 +14,8 @@ export default auth((req: any) => {
|
||||
const studentUrl = process.env.STUDENT_URL ?? 'http://localhost:3000';
|
||||
|
||||
return NextResponse.redirect(new URL(studentUrl, req.url));
|
||||
}) as any;
|
||||
});
|
||||
|
||||
export const config = {
|
||||
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
|
||||
matcher: ['/((?!api|_next/static|_next/image|favicon.ico|login).*)'],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user