({ request, user, match, session, isRunningLocally }: RequestHandlerParams)
| 6 | import { escapeHtml, html } from '/public/ts/utils/misc.ts'; |
| 7 | |
| 8 | async function get({ request, user, match, session, isRunningLocally }: RequestHandlerParams) { |
| 9 | const isSingleSignOnEnabled = await AppConfig.isSingleSignOnEnabled(); |
| 10 | |
| 11 | if (user || !isSingleSignOnEnabled) { |
| 12 | return new Response('Redirect', { status: 303, headers: { 'Location': `/` } }); |
| 13 | } |
| 14 | |
| 15 | let error = ''; |
| 16 | |
| 17 | try { |
| 18 | const { response } = await OidcModel.validateAndCreateSession(request); |
| 19 | |
| 20 | return response; |
| 21 | } catch (validationError) { |
| 22 | console.error(validationError); |
| 23 | error = (validationError as Error).message; |
| 24 | } |
| 25 | |
| 26 | const htmlContent = defaultHtmlContent({ error }); |
| 27 | |
| 28 | return basicLayoutResponse(htmlContent, { |
| 29 | currentPath: match.pathname.input, |
| 30 | titlePrefix: 'Login with SSO', |
| 31 | match, |
| 32 | request, |
| 33 | user, |
| 34 | session, |
| 35 | isRunningLocally, |
| 36 | }); |
| 37 | } |
| 38 | |
| 39 | function defaultHtmlContent({ error }: { error: string }) { |
| 40 | return html` |
nothing calls this directly
no test coverage detected