import page, { RequestHandlerParams } from '/lib/page.ts'; import { AppConfig } from '/lib/config.ts'; import { OidcModel } from '/lib/models/oidc.ts'; import { basicLayoutResponse } from '/lib/utils/layout.tsx'; import { escapeHtml, html } from '/public/ts/utils/misc.ts'; async function get({ request, user, match, session, isRunningLocally }: RequestHandlerParams) { const isSingleSignOnEnabled = await AppConfig.isSingleSignOnEnabled(); if (user || !isSingleSignOnEnabled) { return new Response('Redirect', { status: 303, headers: { 'Location': `/` } }); } let error = ''; try { const { response } = await OidcModel.validateAndCreateSession(request); return response; } catch (validationError) { console.error(validationError); error = (validationError as Error).message; } const htmlContent = defaultHtmlContent({ error }); return basicLayoutResponse(htmlContent, { currentPath: match.pathname.input, titlePrefix: 'Login with SSO', match, request, user, session, isRunningLocally, }); } function defaultHtmlContent({ error }: { error: string }) { return html`

Login with SSO

${error ? html`

Failed to login!

${escapeHtml(error)}

` : ''}

Go back?

Go back to login.

`; } export default page({ get, accessMode: 'public', });