These are now defined in Netlify UI for dedicated environments (test, stage, production): AUTH_URL NEXTAUTH_URL PUBLIC_URL Code now falls back to incoming request host. Mainly used for deployment previews which do not have Akamai in front, meaning we do not need the above workaround as incoming request host matches the actual public facing host. When Akamai is in front, we lose the public facing host in Netlify's routing layer as they internally use `x-forwarded-for` and we can't claim it for our usage.
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { NextResponse } from "next/server"
|
|
|
|
import { env } from "@/env/server"
|
|
import { badRequest, internalServerError } from "@/server/errors/next"
|
|
import { getPublicURL } from "@/server/utils"
|
|
|
|
import { findLang } from "@/utils/languages"
|
|
|
|
import type { NextMiddleware } from "next/server"
|
|
|
|
import type { MiddlewareMatcher } from "@/types/middleware"
|
|
|
|
export const middleware: NextMiddleware = (request) => {
|
|
const currentwebUrl = request.nextUrl.searchParams.get("currentweb")
|
|
if (currentwebUrl == null || undefined) {
|
|
return badRequest()
|
|
}
|
|
const lang = findLang(request.nextUrl.pathname)!
|
|
|
|
const redirectTo = getPublicURL(request)
|
|
|
|
const headers = new Headers(request.headers)
|
|
headers.set("x-returnurl", redirectTo)
|
|
headers.set("x-logout-source", "seamless")
|
|
|
|
return NextResponse.rewrite(new URL(`/${lang}/logout`, request.nextUrl), {
|
|
request: {
|
|
headers,
|
|
},
|
|
})
|
|
}
|
|
export const matcher: MiddlewareMatcher = (request) => {
|
|
return request.nextUrl.pathname.endsWith("/updatelogout")
|
|
}
|