Files
gestion-materiaux-destock/src/middleware.ts
T
2026-06-07 00:05:28 +02:00

28 lines
633 B
TypeScript

import { withAuth } from 'next-auth/middleware'
import { NextResponse } from 'next/server'
export default withAuth(
function middleware(req) {
const { token } = req.nextauth
const { pathname } = req.nextUrl
// Seuls les admins accèdent à /parametres
if (pathname.startsWith('/parametres') && token?.role !== 'admin') {
return NextResponse.redirect(new URL('/', req.url))
}
return NextResponse.next()
},
{
callbacks: {
authorized: ({ token }) => !!token,
},
}
)
export const config = {
matcher: [
'/((?!login|api/auth|_next/static|_next/image|favicon\\.ico).*)',
],
}