38dc6efc09
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
28 lines
633 B
TypeScript
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).*)',
|
|
],
|
|
}
|