fix: move logic to middleware
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import { findLang } from "@/constants/languages"
|
||||
import { badRequest } from "@/server/errors/next"
|
||||
import { findLang, Lang } from "@/constants/languages"
|
||||
import { env } from "@/env/server"
|
||||
import { badRequest, internalServerError } from "@/server/errors/next"
|
||||
|
||||
import type { NextMiddleware } from "next/server"
|
||||
|
||||
@@ -14,9 +15,20 @@ export const middleware: NextMiddleware = (request) => {
|
||||
}
|
||||
const lang = findLang(request.nextUrl.pathname)!
|
||||
|
||||
return NextResponse.rewrite(new URL(`/${lang}/logout`, request.nextUrl))
|
||||
}
|
||||
if (!env.PUBLIC_URL) {
|
||||
throw internalServerError("No value for env.PUBLIC_URL")
|
||||
}
|
||||
const redirectTo = env.PUBLIC_URL
|
||||
|
||||
export const matcher: MiddlewareMatcher = (request) => {
|
||||
return request.nextUrl.pathname.includes("/updatelogout")
|
||||
const headers = new Headers(request.headers)
|
||||
headers.set("x-returnurl", redirectTo)
|
||||
|
||||
return NextResponse.rewrite(new URL(`/${lang}/logout`, request.nextUrl), {
|
||||
request: {
|
||||
headers,
|
||||
},
|
||||
})
|
||||
}
|
||||
export const matcher: MiddlewareMatcher = (request) => {
|
||||
return request.nextUrl.pathname.endsWith("/updatelogout")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user