From 6d6dfe231662be186a68c586c5befd02b3e681a7 Mon Sep 17 00:00:00 2001 From: Jonas Hungershausen Date: Mon, 18 Sep 2023 14:08:03 +0200 Subject: [PATCH 1/2] feat: allow additional partials in templates --- src/pkg/route.ts | 4 ++++ src/routes/login.ts | 4 +++- src/routes/registration.ts | 4 +++- views/login.hbs | 3 +++ views/registration.hbs | 3 +++ 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/pkg/route.ts b/src/pkg/route.ts index 8fcdd30b..4eb0e169 100644 --- a/src/pkg/route.ts +++ b/src/pkg/route.ts @@ -20,6 +20,10 @@ export interface RouteOptions { faviconUrl?: string faviconType?: string theme?: Theme + extraPartials?: { + login: () => string + registration: () => string + } } export type RouteOptionsCreator = (req: Request, res: Response) => RouteOptions diff --git a/src/routes/login.ts b/src/routes/login.ts index d7e75cf9..11667b88 100644 --- a/src/routes/login.ts +++ b/src/routes/login.ts @@ -30,7 +30,8 @@ export const createLoginRoute: RouteCreator = organization = "", login_challenge, } = req.query - const { frontend, kratosBrowserUrl, logoUrl } = createHelpers(req, res) + const { frontend, kratosBrowserUrl, logoUrl, extraPartials } = + createHelpers(req, res) const initFlowQuery = new URLSearchParams({ aal: aal.toString(), @@ -195,6 +196,7 @@ export const createLoginRoute: RouteCreator = }, { locale: res.locals.lang }, ), + extraPartial: extraPartials?.login, }) }) .catch(redirectOnSoftError(res, next, initFlowUrl)) diff --git a/src/routes/registration.ts b/src/routes/registration.ts index cd9f8cc8..6cb1c7cb 100644 --- a/src/routes/registration.ts +++ b/src/routes/registration.ts @@ -29,7 +29,8 @@ export const createRegistrationRoute: RouteCreator = login_challenge, organization, } = req.query - const { frontend, kratosBrowserUrl, logoUrl } = createHelpers(req, res) + const { frontend, kratosBrowserUrl, logoUrl, extraPartials } = + createHelpers(req, res) const initFlowQuery = new URLSearchParams({ ...(return_to && { return_to: return_to.toString() }), @@ -107,6 +108,7 @@ export const createRegistrationRoute: RouteCreator = }, { locale: res.locals.lang }, ), + extraPartial: extraPartials?.registration, }) }) .catch(redirectOnSoftError(res, next, initFlowUrl)) diff --git a/views/login.hbs b/views/login.hbs index c2d013a6..79c5b658 100644 --- a/views/login.hbs +++ b/views/login.hbs @@ -2,4 +2,7 @@ {{{card}}} {{> webauthn_setup nodes=nodes webAuthnHandler=webAuthnHandler webauthnTriggerName="webauthn_login_trigger"}} + {{#if extraPartial }} + {{> (extraPartial) }} + {{/if}} diff --git a/views/registration.hbs b/views/registration.hbs index 9dbdfe77..c1f32e68 100644 --- a/views/registration.hbs +++ b/views/registration.hbs @@ -3,4 +3,7 @@ {{{card}}} {{> webauthn_setup nodes=nodes webAuthnHandler=webAuthnHandler webauthnTriggerName="webauthn_register_trigger"}} + {{#if extraPartial }} + {{> (extraPartial) }} + {{/if}} From 756aee506289d31850480f8e31506395f05ab041 Mon Sep 17 00:00:00 2001 From: Jonas Hungershausen Date: Mon, 18 Sep 2023 14:35:27 +0200 Subject: [PATCH 2/2] chore: add extraContext object --- src/routes/login.ts | 1 + src/routes/registration.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/routes/login.ts b/src/routes/login.ts index 11667b88..b45bd8d1 100644 --- a/src/routes/login.ts +++ b/src/routes/login.ts @@ -197,6 +197,7 @@ export const createLoginRoute: RouteCreator = { locale: res.locals.lang }, ), extraPartial: extraPartials?.login, + extraContext: res.locals.extraContext, }) }) .catch(redirectOnSoftError(res, next, initFlowUrl)) diff --git a/src/routes/registration.ts b/src/routes/registration.ts index 6cb1c7cb..37f74710 100644 --- a/src/routes/registration.ts +++ b/src/routes/registration.ts @@ -109,6 +109,7 @@ export const createRegistrationRoute: RouteCreator = { locale: res.locals.lang }, ), extraPartial: extraPartials?.registration, + extraContext: res.locals.extraContext, }) }) .catch(redirectOnSoftError(res, next, initFlowUrl))