From 2ac36832bcd9ddfc75d2a59d3f4e13c0e84512d9 Mon Sep 17 00:00:00 2001 From: Maciej Krawczyk <63869461+wzarek@users.noreply.github.com> Date: Sun, 23 Jun 2024 17:31:38 +0200 Subject: [PATCH] feat: changed middleware --- Client/reasn-client/apps/web/middleware.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Client/reasn-client/apps/web/middleware.ts b/Client/reasn-client/apps/web/middleware.ts index 2ac530b..1b59c67 100644 --- a/Client/reasn-client/apps/web/middleware.ts +++ b/Client/reasn-client/apps/web/middleware.ts @@ -9,6 +9,10 @@ export const middleware = (req: NextRequest) => { const isAuthPath = path.startsWith("/login") || path.startsWith("/register"); + if (path.startsWith("/user") && session.user?.role !== UserRole.ADMIN) { + return NextResponse.redirect(new URL(path.replace("/edit", ""), req.url)); + } + if (!session.isAuthenticated()) { if (isAuthPath) return NextResponse.next(); return NextResponse.redirect(new URL("/login", req.url)); @@ -20,15 +24,16 @@ export const middleware = (req: NextRequest) => { if (path.startsWith("/events") && session.user?.role === UserRole.USER) { return NextResponse.redirect(new URL("/events", req.url)); - } + } }; export const config = { matcher: [ "/events/new", "/events/(.*)/(.*)", - // "/me", - // "/me/(.*)", + "/me", + "/me/(.*)", + "/user/(.*)/edit", "/login", "/register", "/register/(.*)",