Skip to content

Commit

Permalink
feat: allow external partials on login & registration (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-jonas authored Sep 19, 2023
1 parent 768fafd commit 7d0e864
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/pkg/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/routes/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -195,6 +196,8 @@ export const createLoginRoute: RouteCreator =
},
{ locale: res.locals.lang },
),
extraPartial: extraPartials?.login,
extraContext: res.locals.extraContext,
})
})
.catch(redirectOnSoftError(res, next, initFlowUrl))
Expand Down
5 changes: 4 additions & 1 deletion src/routes/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() }),
Expand Down Expand Up @@ -107,6 +108,8 @@ export const createRegistrationRoute: RouteCreator =
},
{ locale: res.locals.lang },
),
extraPartial: extraPartials?.registration,
extraContext: res.locals.extraContext,
})
})
.catch(redirectOnSoftError(res, next, initFlowUrl))
Expand Down
3 changes: 3 additions & 0 deletions views/login.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
{{{card}}}

{{> webauthn_setup nodes=nodes webAuthnHandler=webAuthnHandler webauthnTriggerName="webauthn_login_trigger"}}
{{#if extraPartial }}
{{> (extraPartial) }}
{{/if}}
</div>
3 changes: 3 additions & 0 deletions views/registration.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
{{{card}}}

{{> webauthn_setup nodes=nodes webAuthnHandler=webAuthnHandler webauthnTriggerName="webauthn_register_trigger"}}
{{#if extraPartial }}
{{> (extraPartial) }}
{{/if}}
</div>

0 comments on commit 7d0e864

Please sign in to comment.