21 lines
624 B
TypeScript
21 lines
624 B
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import createMiddleware from 'next-intl/middleware'
|
|
import { auth } from '@/lib/auth'
|
|
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()
|
|
if (!session || (session.user as any)?.role !== 'ADMIN') {
|
|
return NextResponse.redirect(new URL('/login', request.url))
|
|
}
|
|
}
|
|
return intlMiddleware(request)
|
|
}
|
|
|
|
export const config = {
|
|
matcher: ['/((?!api|_next|_vercel|.*\\..*).*)']
|
|
}
|