Skip to content

Commit

Permalink
feat: changed middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
wzarek committed Jun 23, 2024
1 parent 0b35914 commit 2ac3683
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Client/reasn-client/apps/web/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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/(.*)",
Expand Down

0 comments on commit 2ac3683

Please sign in to comment.