fix: rewriting rules for my-pages

This commit is contained in:
Michael Zetterberg
2024-05-16 15:22:39 +02:00
parent f1682b5a15
commit 5e3041a73a
18 changed files with 150 additions and 282 deletions

View File

@@ -3,7 +3,6 @@ import { NextResponse } from "next/server"
import { findLang } from "@/constants/languages"
import { authRequired } from "@/constants/routes/authRequired"
import { login } from "@/constants/routes/handleAuth"
import { benefits, myPages, overview, stays } from "@/constants/routes/myPages"
import { auth } from "@/auth"
@@ -43,23 +42,6 @@ export const middleware = auth(async (request) => {
const isLoggedIn = !!request.auth
if (isLoggedIn) {
const pathNameWithoutLang = nextUrl.pathname.replace(`/${lang}`, "")
// Temp fix until we have a better solution for identifying AccountPage type
const accountPagePaths = [
myPages[lang],
overview[lang],
benefits[lang],
stays[lang],
]
if (accountPagePaths.includes(nextUrl.pathname)) {
const searchParams = new URLSearchParams(request.nextUrl.searchParams)
searchParams.set("uri", pathNameWithoutLang)
return NextResponse.rewrite(
new URL(`/${lang}/my-pages?${searchParams.toString()}`, nextUrl)
)
}
return NextResponse.next()
}