From e65145687d74fc0f7a2c23cf3732cbc873f56fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matilda=20Landstr=C3=B6m?= Date: Wed, 22 May 2024 11:03:26 +0200 Subject: [PATCH] chore: add back language specific routes --- .env.local.example | 7 +++- app/[lang]/(live)/(protected)/logout/route.ts | 32 ++++++++++++++++--- env/server.ts | 14 ++++++-- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/.env.local.example b/.env.local.example index 05ebae40e..721213c83 100644 --- a/.env.local.example +++ b/.env.local.example @@ -26,4 +26,9 @@ SEAMLESS_LOGIN_EN="http://www.example.com/updatelogin" SEAMLESS_LOGIN_FI="http://www.example.fi/updatelogin" SEAMLESS_LOGIN_NO="http://www.example.no/updatelogin" SEAMLESS_LOGIN_SV="http://www.example.se/updatelogin" -SEAMLESS_LOGOUT="http://www.example.com/updatelogout?newweb" +SEAMLESS_LOGOUT_DA="http://www.example.dk/updatelogout?newweb" +SEAMLESS_LOGOUT_DE="http://www.example.de/updatelogout?newweb" +SEAMLESS_LOGOUT_EN="http://www.example.com/updatelogout?newweb" +SEAMLESS_LOGOUT_FI="http://www.example.fi/updatelogout?newweb" +SEAMLESS_LOGOUT_NO="http://www.example.no/updatelogout?newweb" +SEAMLESS_LOGOUT_SV="http://www.example.sv/updatelogout?newweb" diff --git a/app/[lang]/(live)/(protected)/logout/route.ts b/app/[lang]/(live)/(protected)/logout/route.ts index 55648c386..73781abf4 100644 --- a/app/[lang]/(live)/(protected)/logout/route.ts +++ b/app/[lang]/(live)/(protected)/logout/route.ts @@ -3,19 +3,22 @@ import { headers as nextHeaders } from "next/headers" import { NextRequest, NextResponse } from "next/server" import { AuthError } from "next-auth" +import { Lang } from "@/constants/languages" import { env } from "@/env/server" -import { serverClient } from "@/lib/trpc/server" import { internalServerError } from "@/server/errors/next" import { signOut } from "@/auth" -export async function GET(request: NextRequest) { +export async function GET( + request: NextRequest, + context: { params: { lang: Lang } } +) { let redirectHeaders: Headers | undefined = undefined let redirectTo: string const returnUrl = request.headers.get("x-returnurl") + console.log("TESTING", returnUrl) if (returnUrl) { - // Should check for ?currentweb in header? redirectTo = returnUrl } else { // Normal logout request from New web @@ -40,7 +43,28 @@ export async function GET(request: NextRequest) { try { // Initiate the seamless logout flow - const redirectUrl = new URL(env.SEAMLESS_LOGOUT) + let redirectUrlValue + switch (context.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 + } + const redirectUrl = new URL(redirectUrlValue) redirectUrl.searchParams.set("returnurl", redirectTo) redirectTo = redirectUrl.toString() } catch (e) { diff --git a/env/server.ts b/env/server.ts index 04eeabf62..7a01807d8 100644 --- a/env/server.ts +++ b/env/server.ts @@ -48,7 +48,12 @@ export const env = createEnv({ SEAMLESS_LOGIN_FI: z.string(), SEAMLESS_LOGIN_NO: z.string(), SEAMLESS_LOGIN_SV: z.string(), - SEAMLESS_LOGOUT: z.string(), + SEAMLESS_LOGOUT_DA: z.string(), + SEAMLESS_LOGOUT_DE: z.string(), + SEAMLESS_LOGOUT_EN: z.string(), + SEAMLESS_LOGOUT_FI: z.string(), + SEAMLESS_LOGOUT_NO: z.string(), + SEAMLESS_LOGOUT_SV: z.string(), WEBVIEW_ENCRYPTION_KEY: z.string(), }, emptyStringAsUndefined: true, @@ -83,7 +88,12 @@ export const env = createEnv({ SEAMLESS_LOGIN_FI: process.env.SEAMLESS_LOGIN_FI, SEAMLESS_LOGIN_NO: process.env.SEAMLESS_LOGIN_NO, SEAMLESS_LOGIN_SV: process.env.SEAMLESS_LOGIN_SV, - SEAMLESS_LOGOUT: process.env.SEAMLESS_LOGOUT, + SEAMLESS_LOGOUT_DA: process.env.SEAMLESS_LOGOUT_DA, + SEAMLESS_LOGOUT_DE: process.env.SEAMLESS_LOGOUT_DE, + SEAMLESS_LOGOUT_EN: process.env.SEAMLESS_LOGOUT_EN, + SEAMLESS_LOGOUT_FI: process.env.SEAMLESS_LOGOUT_FI, + SEAMLESS_LOGOUT_NO: process.env.SEAMLESS_LOGOUT_NO, + SEAMLESS_LOGOUT_SV: process.env.SEAMLESS_LOGOUT_SV, WEBVIEW_ENCRYPTION_KEY: process.env.WEBVIEW_ENCRYPTION_KEY, }, })