From d45f79a3d937fdc358fa58c69dd155e73950c484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi?= Date: Sun, 5 Jan 2025 02:10:54 +0100 Subject: [PATCH] feat: protect admin routes with OIDC roles --- src/middleware.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/middleware.ts b/src/middleware.ts index 4dff0c1..f719a28 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -17,6 +17,14 @@ export async function middleware(req: NextRequest) { return NextResponse.redirect(url); } + if ( + !token?.user.roles.includes("admin") && + url.pathname.startsWith("/admin") + ) { + url.pathname = "/"; + return NextResponse.redirect(url); + } + return NextResponse.next(); }