Merged in feat/loy-403-seamless (pull request #3164)

feat(LOY-403): removed seamless login/logout

* feat(LOY-403): removed seamless login/logout


Approved-by: Joakim Jäderberg
This commit is contained in:
Linus Flood
2025-11-17 09:58:15 +00:00
parent 6424291ade
commit 93c481fea8
10 changed files with 10 additions and 310 deletions

View File

@@ -1,7 +1,6 @@
import { type NextRequest, NextResponse } from "next/server"
import { AuthError } from "next-auth"
import { Lang } from "@scandic-hotels/common/constants/language"
import { logger } from "@scandic-hotels/common/logger"
import { env } from "@/env/server"
@@ -10,17 +9,11 @@ import { getPublicURL } from "@/server/utils"
import { signOut } from "@/auth"
export async function GET(
request: NextRequest,
context: RouteContext<"/[lang]/logout">
) {
export async function GET(request: NextRequest) {
const publicURL = getPublicURL(request)
let redirectTo: string = ""
const returnUrl = request.headers.get("x-returnurl")
const isSeamless = request.headers.get("x-logout-source") === "seamless"
logger.debug(
`[logout] source: ${request.headers.get("x-logout-source") || "normal"}`
)
@@ -29,62 +22,13 @@ export async function GET(
request.nextUrl.searchParams.get("redirectTo")
const redirectToFallback = "/"
if (isSeamless) {
if (returnUrl) {
redirectTo = returnUrl
} else {
logger.debug(
`[login] missing returnUrl, using fallback: ${redirectToFallback}`
)
redirectTo = redirectToFallback
}
} else {
redirectTo = redirectToSearchParamValue || redirectToFallback
redirectTo = redirectToSearchParamValue || redirectToFallback
// Make relative URL to absolute URL
if (redirectTo.startsWith("/")) {
logger.debug(`[logout] make redirectTo absolute, from ${redirectTo}`)
redirectTo = new URL(redirectTo, publicURL).href
logger.debug(`[logout] make redirectTo absolute, to ${redirectTo}`)
}
try {
// Initiate the seamless logout flow
let redirectUrlValue
const params = await context.params
switch (params.lang) {
case Lang.da:
redirectUrlValue = env.SEAMLESS_LOGOUT_DA
break
case Lang.de:
redirectUrlValue = env.SEAMLESS_LOGOUT_DE
break
case Lang.en:
redirectUrlValue = env.SEAMLESS_LOGOUT_EN
break
case Lang.fi:
redirectUrlValue = env.SEAMLESS_LOGOUT_FI
break
case Lang.no:
redirectUrlValue = env.SEAMLESS_LOGOUT_NO
break
case Lang.sv:
redirectUrlValue = env.SEAMLESS_LOGOUT_SV
break
default:
throw new Error(`Unsupported language for logout: ${params.lang}`)
}
const redirectUrl = new URL(redirectUrlValue)
logger.debug(
`[logout] creating redirect to seamless logout: ${redirectUrl}`
)
redirectTo = redirectUrl.toString()
} catch (e) {
logger.error(
"Unable to create URL for seamless logout, proceeding without it.",
e
)
}
// Make relative URL to absolute URL
if (redirectTo.startsWith("/")) {
logger.debug(`[logout] make redirectTo absolute, from ${redirectTo}`)
redirectTo = new URL(redirectTo, publicURL).href
logger.debug(`[logout] make redirectTo absolute, to ${redirectTo}`)
}
try {

View File

@@ -1,10 +1,8 @@
import { type NextRequest, NextResponse } from "next/server"
import { AuthError } from "next-auth"
import { Lang } from "@scandic-hotels/common/constants/language"
import { logger } from "@scandic-hotels/common/logger"
import { env } from "@/env/server"
import { internalServerError } from "@/server/errors/next"
import { getPublicURL } from "@/server/utils"
@@ -21,7 +19,6 @@ export async function GET(
let redirectTo: string
const returnUrl = request.headers.get("x-returnurl")
const isSeamless = request.headers.get("x-login-source") === "seamless"
const isMFA = request.headers.get("x-login-source") === "mfa"
const isSeamlessMagicLink =
request.headers.get("x-login-source") === "seamless-magiclink"
@@ -40,7 +37,7 @@ export async function GET(
`[login] redirectTo search param value: ${redirectToSearchParamValue}`
)
if (isSeamless || isSeamlessMagicLink || isMFA) {
if (isSeamlessMagicLink || isMFA) {
if (returnUrl) {
redirectTo = returnUrl
} else {
@@ -66,57 +63,6 @@ export async function GET(
"set-cookie",
"redirectTo=; Expires=Thu, 01 Jan 1970 00:00:00 UTC; Path=/; HttpOnly; SameSite=Lax"
)
try {
// Initiate the seamless login flow
let redirectUrlValue
switch (contextParams.lang) {
case Lang.da:
redirectUrlValue = env.SEAMLESS_LOGIN_DA
break
case Lang.de:
redirectUrlValue = env.SEAMLESS_LOGIN_DE
break
case Lang.en:
redirectUrlValue = env.SEAMLESS_LOGIN_EN
break
case Lang.fi:
redirectUrlValue = env.SEAMLESS_LOGIN_FI
break
case Lang.no:
redirectUrlValue = env.SEAMLESS_LOGIN_NO
break
case Lang.sv:
redirectUrlValue = env.SEAMLESS_LOGIN_SV
break
default:
throw new Error(
`Unsupported language for login: ${contextParams.lang}`
)
}
const redirectUrl = new URL(redirectUrlValue)
logger.debug(
`[login] creating redirect to seamless login: ${redirectUrl}`
)
redirectUrl.searchParams.set("returnurl", redirectTo)
logger.debug(
`[login] returnurl for seamless login: ${redirectUrl.searchParams.get("returnurl")}`
)
redirectTo = redirectUrl.toString()
/** Set cookie with redirect Url to appropriately redirect user when using magic link login */
redirectHeaders.append(
"set-cookie",
"magicLinkRedirectTo=" +
redirectTo +
"; Max-Age=300; Path=/; HttpOnly; SameSite=Lax"
)
} catch (e) {
logger.error(
"[login] unable to create URL for seamless login, proceeding without it.",
e
)
}
}
try {