Skip to content

Commit

Permalink
fix: Infinite redirection issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed Jul 10, 2024
1 parent b99ea59 commit f0e0b62
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export function middleware(request: NextRequest) {

const currentUser = request.cookies.get("currentUser")?.value

if (!currentUser && request.nextUrl.pathname.includes("forgot_password")) {
return NextResponse.next()
}

if (!currentUser && request.nextUrl.pathname.includes("reset_password")) {
if (
!currentUser &&
(request.nextUrl.pathname.includes("forgot_password") ||
request.nextUrl.pathname.includes("reset_password"))
) {
return NextResponse.next()
}

Expand All @@ -35,15 +35,6 @@ export function middleware(request: NextRequest) {
)
}

if (currentUser && Date.now() > JSON.parse(currentUser).expired_at) {
request.cookies.delete("currentUser")
const response = NextResponse.redirect(
new URL("/auth/login?redirect=" + urlBeforeRedirect, request.url)
)
response.cookies.delete("currentUser")
return response
}

if (currentUser && authRoutes.includes(request.nextUrl.pathname)) {
let url = request.nextUrl.searchParams.get("redirect") || "/"
return NextResponse.redirect(new URL(url, request.url))
Expand Down

0 comments on commit f0e0b62

Please sign in to comment.