Merged in feat/sw-3192-no-user (pull request #2680)
feat(SW-3192): Checks if user exists, otherwise logout and show error * feat(SW-3192): Checks if user exists, otherwise logout and show error
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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()
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { UserNotFound } from "@/components/UserNotFound/UserNotFound"
|
||||
|
||||
import type { Metadata } from "next"
|
||||
|
||||
export const metadata: Metadata = {
|
||||
robots: {
|
||||
index: false,
|
||||
follow: false,
|
||||
},
|
||||
}
|
||||
|
||||
export default function UserNotFoundPage() {
|
||||
return <UserNotFound />
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import SitewideAlert from "@/components/SitewideAlert"
|
||||
import { ToastHandler } from "@/components/TempDesignSystem/Toasts"
|
||||
import AdobeSDKScript from "@/components/TrackingSDK/AdobeSDKScript"
|
||||
import GTMScript from "@/components/TrackingSDK/GTMScript"
|
||||
import { UserExists } from "@/components/UserExists"
|
||||
import { FontPreload } from "@/fonts/font-preloading"
|
||||
import { getMessages } from "@/i18n"
|
||||
import ClientIntlProvider from "@/i18n/Provider"
|
||||
@@ -87,6 +88,7 @@ export default async function RootLayout(
|
||||
<SessionRefresher />
|
||||
<StorageCleaner />
|
||||
<CookieBotConsent />
|
||||
<UserExists />
|
||||
<ReactQueryDevtools initialIsOpen={false} />
|
||||
</BookingFlowTrackingProvider>
|
||||
</RACRouterProvider>
|
||||
|
||||
Reference in New Issue
Block a user