Files
web/apps/scandic-web/app/[lang]/(live)/(public)/dtmc/route.ts
Chuma Mcphoy (We Ahead) df7b8ca7dd Merged in fix/use-image-component-for-dtmc-link-error (pull request #2515)
Use component image for dtmc error page bg

* Use component image for dtmc error page bg


Approved-by: Joakim Jäderberg
Approved-by: Anton Gunnarsson
Approved-by: Matilda Landström
2025-07-03 13:23:32 +00:00

49 lines
1.4 KiB
TypeScript

import { type NextRequest, NextResponse } from "next/server"
import { AuthError } from "next-auth"
import { logger } from "@scandic-hotels/common/logger"
import { dtmcApiCallback } from "@/constants/routes/dtmc"
import { internalServerError, serviceUnavailable } from "@/server/errors/next"
import { getPublicURL } from "@/server/utils"
import { signIn } from "@/auth.dtmc"
export async function GET(request: NextRequest) {
const publicURL = getPublicURL(request)
try {
const redirectUrl = await signIn(
"microsoft-entra-id",
{
redirectTo: `${publicURL}${dtmcApiCallback}`,
redirect: false,
},
{
prompt: "login",
}
)
if (redirectUrl) {
logger.debug(`[dtmc] redirecting to: ${redirectUrl}`)
return NextResponse.redirect(redirectUrl)
} else {
logger.error(`[dtmc] missing redirectUrl response from signIn()`)
return internalServerError(
"[dtmc] Missing redirect URL from authentication service"
)
}
} catch (error) {
if (error instanceof AuthError) {
logger.error("signInAuthError", { signInAuthError: error })
return serviceUnavailable(
"[dtmc] Microsoft authentication service unavailable"
)
} else {
logger.error("signInError", { signInError: error })
return internalServerError(
"[dtmc] Unexpected error during authentication"
)
}
}
}