fix(WEB-132): absolute seamless login return urls
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
import { findLang } from "@/constants/languages"
|
||||
import { authRequired } from "@/constants/routes/authRequired"
|
||||
import { login } from "@/constants/routes/handleAuth"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
|
||||
import type { NextMiddleware } from "next/server"
|
||||
|
||||
import type { MiddlewareMatcher } from "@/types/middleware"
|
||||
@@ -44,8 +45,15 @@ export const middleware = auth(async (request) => {
|
||||
return NextResponse.next()
|
||||
}
|
||||
|
||||
const headers = new Headers()
|
||||
headers.append(
|
||||
"set-cookie",
|
||||
`redirectTo=${encodeURIComponent(nextUrl.href)}; Path=/; HttpOnly; SameSite=Lax`
|
||||
)
|
||||
const loginUrl = login[lang]
|
||||
return NextResponse.redirect(new URL(loginUrl, request.nextUrl))
|
||||
return NextResponse.redirect(new URL(loginUrl, request.nextUrl), {
|
||||
headers,
|
||||
})
|
||||
}) as NextMiddleware // See comment above
|
||||
|
||||
export const matcher: MiddlewareMatcher = (request) => {
|
||||
|
||||
Reference in New Issue
Block a user