Update application features and add scripts (core changes)
This commit is contained in:
@@ -5,15 +5,22 @@ import { routing } from '@/i18n/routing'
|
||||
|
||||
const intlMiddleware = createMiddleware(routing)
|
||||
|
||||
export async function proxy(request: NextRequest) {
|
||||
if (request.nextUrl.pathname.includes('/admin')) {
|
||||
const session = await auth()
|
||||
export const proxy = auth((request) => {
|
||||
const isAuthOrAdmin = request.nextUrl.pathname.startsWith('/admin') || request.nextUrl.pathname.startsWith('/login')
|
||||
|
||||
if (request.nextUrl.pathname.startsWith('/admin')) {
|
||||
const session = request.auth
|
||||
if (!session || (session.user as any)?.role !== 'ADMIN') {
|
||||
return NextResponse.redirect(new URL('/login', request.url))
|
||||
}
|
||||
}
|
||||
|
||||
if (isAuthOrAdmin) {
|
||||
return NextResponse.next()
|
||||
}
|
||||
|
||||
return intlMiddleware(request)
|
||||
}
|
||||
})
|
||||
|
||||
export const config = {
|
||||
matcher: ['/((?!api|_next|_vercel|.*\\..*).*)']
|
||||
|
||||
Reference in New Issue
Block a user