bug: fix rewrites to profile routes for all languages

This commit is contained in:
Christel Westerberg
2024-07-16 07:56:00 +02:00
parent 87a56448d8
commit 92829108be
2 changed files with 29 additions and 5 deletions

View File

@@ -1,6 +1,11 @@
import { NextResponse } from "next/server"
import { myPages, overview } from "@/constants/routes/myPages"
import {
myPages,
overview,
profile,
profileEdit,
} from "@/constants/routes/myPages"
import { env } from "@/env/server"
import { internalServerError, notFound } from "@/server/errors/next"
@@ -43,6 +48,25 @@ export const middleware: NextMiddleware = async (request) => {
const headers = getDefaultRequestHeaders(request)
headers.set("x-uid", uid)
headers.set("x-contenttype", contentType)
// Handle profile and profile edit routes, which are not CMS entries
if (profile[lang].startsWith(nextUrl.pathname)) {
return NextResponse.rewrite(new URL(`/${lang}/my-pages/profile`, nextUrl), {
request: {
headers,
},
})
} else if (profileEdit[lang].startsWith(nextUrl.pathname)) {
return NextResponse.rewrite(
new URL(`/${lang}/my-pages/profile/edit`, nextUrl),
{
request: {
headers,
},
}
)
}
return NextResponse.next({
request: {
headers,