Merged in feat/LOY-230-Microsoft-Entra-ID-Auth (pull request #2113)
Feat(LOY-230): DTMC Routes with Entra ID Auth & Error Page Handling * feat(LOY-230): Link Scandic Friends and Azure accounts * fix(LOY-230): remove employee id param setting * fix(LOY-230): return token in jwt callback for auth.dtmc.ts Approved-by: Michael Zetterberg Approved-by: Christian Andolf
This commit is contained in:
45
apps/scandic-web/app/[lang]/(live)/(public)/dtmc/route.ts
Normal file
45
apps/scandic-web/app/[lang]/(live)/(public)/dtmc/route.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import { AuthError } from "next-auth"
|
||||
|
||||
import { dtmcApiCallback } from "@/constants/routes/dtmc"
|
||||
import { env } from "@/env/server"
|
||||
import { internalServerError, serviceUnavailable } from "@/server/errors/next"
|
||||
|
||||
import { signIn } from "@/auth.dtmc"
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const redirectUrl = await signIn(
|
||||
"microsoft-entra-id",
|
||||
{
|
||||
redirectTo: `${env.PUBLIC_URL}${dtmcApiCallback}`,
|
||||
redirect: false,
|
||||
},
|
||||
{
|
||||
prompt: "login",
|
||||
}
|
||||
)
|
||||
|
||||
if (redirectUrl) {
|
||||
console.log(`[dtmc] redirecting to: ${redirectUrl}`)
|
||||
return NextResponse.redirect(redirectUrl)
|
||||
} else {
|
||||
console.error(`[dtmc] missing redirectUrl response from signIn()`)
|
||||
return internalServerError(
|
||||
"[dtmc] Missing redirect URL from authentication service"
|
||||
)
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError) {
|
||||
console.error({ signInAuthError: error })
|
||||
return serviceUnavailable(
|
||||
"[dtmc] Microsoft authentication service unavailable"
|
||||
)
|
||||
} else {
|
||||
console.error({ signInError: error })
|
||||
return internalServerError(
|
||||
"[dtmc] Unexpected error during authentication"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user