Skip to content

Commit

Permalink
fix(): middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Limerio committed Apr 28, 2024
1 parent 120bd53 commit 6f3a5c9
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/middleware.js
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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") &&
Expand All @@ -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))
}

Expand All @@ -31,5 +30,3 @@ const middleware = async req => {

return NextResponse.next()
}

export default middleware

0 comments on commit 6f3a5c9

Please sign in to comment.