From 6f3a5c97da4436f19ba81a8af5f62b673d0fdd6b Mon Sep 17 00:00:00 2001 From: Limerio <44976231+Limerio@users.noreply.github.com> Date: Sun, 28 Apr 2024 19:19:49 +0200 Subject: [PATCH] fix(): middleware --- src/middleware.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/middleware.js b/src/middleware.js index 990b86c..41a4acc 100644 --- a/src/middleware.js +++ b/src/middleware.js @@ -1,4 +1,3 @@ -import { UserService } from "@/features/users/services" import { decrypt } from "@/lib/jwt" import { loginRequiredPaths } from "@/utils/constants" import { NextResponse } from "next/server" @@ -8,7 +7,7 @@ import { NextResponse } from "next/server" * @param {import("next/server").NextRequest} req * @returns */ -const middleware = async req => { +export const middleware = async req => { if ( loginRequiredPaths.find(path => path === req.nextUrl.pathname) || (req.nextUrl.pathname.startsWith("/places") && @@ -22,7 +21,7 @@ const middleware = async req => { const { user } = await decrypt(sessionToken) - if (!(await UserService.exists({ username: user.username }))) { + if (!user?.username) { return NextResponse.rewrite(new URL("/login", req.url)) } @@ -31,5 +30,3 @@ const middleware = async req => { return NextResponse.next() } - -export default middleware