SW-3270 move interactive map to design system or booking flow * wip * wip * merge * wip * add support for locales in design-system * add story for HotelCard * setup alias * . * remove tracking from design-system for hotelcard * pass isUserLoggedIn * export design-system-new-deprecated.css from design-system * Add HotelMarkerByType to Storybook * Add interactive map to Storybook * fix reactintl in vitest * rename env variables * . * fix background colors * add storybook stories for <Link /> * merge * fix tracking for when clicking 'See rooms' in InteractiveMap * Merge branch 'master' of bitbucket.org:scandic-swap/web into SW-3270-move-interactive-map-to-design-system-or-booking-flow * remove deprecated comment Approved-by: Anton Gunnarsson
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { type NextRequest, NextResponse } from "next/server"
|
|
import { AuthError } from "next-auth"
|
|
|
|
import { logger } from "@scandic-hotels/common/logger"
|
|
|
|
import { env } from "@/env/server"
|
|
import { internalServerError } from "@/server/errors/next"
|
|
import { getPublicURL } from "@/server/utils"
|
|
|
|
import { signOut } from "@/auth"
|
|
|
|
export async function GET(request: NextRequest) {
|
|
const publicURL = getPublicURL(request)
|
|
const redirectToSearchParamValue =
|
|
request.nextUrl.searchParams.get("redirectTo")
|
|
const redirectToFallback = "/"
|
|
|
|
let redirectTo: string = redirectToSearchParamValue || redirectToFallback
|
|
|
|
// Make relative URL to absolute URL
|
|
if (redirectTo.startsWith("/")) {
|
|
redirectTo = new URL(redirectTo, publicURL).href
|
|
}
|
|
|
|
try {
|
|
redirectTo = `${env.CURITY_ISSUER_USER}/authn/authenticate/logout?redirect_uri=${encodeURIComponent(redirectTo)}`
|
|
logger.debug(`[logoutSafely] final redirectUrl: ${redirectTo}`)
|
|
|
|
const redirectUrlObj = await signOut({
|
|
redirectTo,
|
|
redirect: false,
|
|
})
|
|
|
|
return NextResponse.redirect(redirectUrlObj.redirect)
|
|
} catch (error) {
|
|
if (error instanceof AuthError) {
|
|
logger.error("signOutSafelyAuthError", { signOutAuthError: error })
|
|
} else {
|
|
logger.error("signOutSafelyError", { signOutError: error })
|
|
}
|
|
}
|
|
|
|
return internalServerError()
|
|
}
|