Merged in feat/book-606-logout-redirect (pull request #3353)
feat(BOOK-606): redirect to /lang when signing out instead of /en * feat(BOOK-606): redirect to /lang when signing out instead of /en Approved-by: Joakim Jäderberg Approved-by: Matilda Landström
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
import { type NextRequest, NextResponse } from "next/server"
|
import { type NextRequest, NextResponse } from "next/server"
|
||||||
import { AuthError } from "next-auth"
|
import { AuthError } from "next-auth"
|
||||||
|
|
||||||
|
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||||
import { logger } from "@scandic-hotels/common/logger"
|
import { logger } from "@scandic-hotels/common/logger"
|
||||||
|
import { isValidLang } from "@scandic-hotels/common/utils/languages"
|
||||||
|
|
||||||
import { env } from "@/env/server"
|
import { env } from "@/env/server"
|
||||||
import { internalServerError } from "@/server/errors/next"
|
import { internalServerError } from "@/server/errors/next"
|
||||||
@@ -9,8 +11,13 @@ import { getPublicURL } from "@/server/utils"
|
|||||||
|
|
||||||
import { signOut } from "@/auth"
|
import { signOut } from "@/auth"
|
||||||
|
|
||||||
export async function GET(request: NextRequest) {
|
export async function GET(
|
||||||
|
request: NextRequest,
|
||||||
|
context: RouteContext<"/[lang]/logout">
|
||||||
|
) {
|
||||||
const publicURL = getPublicURL(request)
|
const publicURL = getPublicURL(request)
|
||||||
|
const params = await context.params
|
||||||
|
const lang = isValidLang(params.lang) ? params.lang : Lang.en
|
||||||
|
|
||||||
let redirectTo: string = ""
|
let redirectTo: string = ""
|
||||||
|
|
||||||
@@ -20,7 +27,7 @@ export async function GET(request: NextRequest) {
|
|||||||
|
|
||||||
const redirectToSearchParamValue =
|
const redirectToSearchParamValue =
|
||||||
request.nextUrl.searchParams.get("redirectTo")
|
request.nextUrl.searchParams.get("redirectTo")
|
||||||
const redirectToFallback = "/"
|
const redirectToFallback = `/${lang}`
|
||||||
|
|
||||||
redirectTo = redirectToSearchParamValue || redirectToFallback
|
redirectTo = redirectToSearchParamValue || redirectToFallback
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { type NextRequest, NextResponse } from "next/server"
|
import { type NextRequest, NextResponse } from "next/server"
|
||||||
import { AuthError } from "next-auth"
|
import { AuthError } from "next-auth"
|
||||||
|
|
||||||
|
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||||
import { logger } from "@scandic-hotels/common/logger"
|
import { logger } from "@scandic-hotels/common/logger"
|
||||||
|
import { isValidLang } from "@scandic-hotels/common/utils/languages"
|
||||||
|
|
||||||
import { env } from "@/env/server"
|
import { env } from "@/env/server"
|
||||||
import { internalServerError } from "@/server/errors/next"
|
import { internalServerError } from "@/server/errors/next"
|
||||||
@@ -9,11 +11,16 @@ import { getPublicURL } from "@/server/utils"
|
|||||||
|
|
||||||
import { signOut } from "@/auth"
|
import { signOut } from "@/auth"
|
||||||
|
|
||||||
export async function GET(request: NextRequest) {
|
export async function GET(
|
||||||
|
request: NextRequest,
|
||||||
|
context: RouteContext<"/[lang]/logoutSafely">
|
||||||
|
) {
|
||||||
const publicURL = getPublicURL(request)
|
const publicURL = getPublicURL(request)
|
||||||
|
const params = await context.params
|
||||||
|
const lang = isValidLang(params.lang) ? params.lang : Lang.en
|
||||||
const redirectToSearchParamValue =
|
const redirectToSearchParamValue =
|
||||||
request.nextUrl.searchParams.get("redirectTo")
|
request.nextUrl.searchParams.get("redirectTo")
|
||||||
const redirectToFallback = "/"
|
const redirectToFallback = `/${lang}`
|
||||||
|
|
||||||
let redirectTo: string = redirectToSearchParamValue || redirectToFallback
|
let redirectTo: string = redirectToSearchParamValue || redirectToFallback
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user