Skip to content

Commit 3b8d045

Browse files
authored
chore: simplify js setup (#320)
1 parent af3395e commit 3b8d045

File tree

8 files changed

+14
-60
lines changed

8 files changed

+14
-60
lines changed

src/routes/login.ts

-12
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,6 @@ export const createLoginRoute: RouteCreator =
173173

174174
res.render("login", {
175175
nodes: flow.ui.nodes,
176-
webAuthnHandler: filterNodesByGroups({
177-
nodes: flow.ui.nodes,
178-
groups: ["webauthn", "passkey"],
179-
attributes: ["button"],
180-
withoutDefaultAttributes: true,
181-
withoutDefaultGroup: true,
182-
})
183-
.filter(({ attributes }) => isUiNodeInputAttributes(attributes))
184-
.map(({ attributes }) => {
185-
return (attributes as UiNodeInputAttributes).onclick
186-
})
187-
.filter((c) => c !== undefined),
188176
card: UserAuthCard(
189177
{
190178
flow,

src/routes/registration.ts

+1-13
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,9 @@ export const createRegistrationRoute: RouteCreator =
7979
flow.oauth2_login_request.challenge,
8080
)
8181
}
82-
const webAuthnHandler = filterNodesByGroups({
83-
nodes: flow.ui.nodes,
84-
groups: ["webauthn", "passkey"],
85-
attributes: ["button"],
86-
withoutDefaultAttributes: true,
87-
withoutDefaultGroup: true,
88-
})
89-
.filter(({ attributes }) => isUiNodeInputAttributes(attributes))
90-
.map(({ attributes }) => {
91-
return (attributes as UiNodeInputAttributes).onclick
92-
})
93-
.filter((onClickAction) => !!onClickAction)
82+
9483
res.render("registration", {
9584
nodes: flow.ui.nodes,
96-
webAuthnHandler: webAuthnHandler,
9785
card: UserAuthCard(
9886
{
9987
flow,

src/routes/settings.ts

-12
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,6 @@ export const createSettingsRoute: RouteCreator =
7777
nodes: flow.ui.nodes,
7878
nav: settingsScreen.Nav,
7979
settingsScreen: settingsScreen.Body,
80-
webAuthnHandler: filterNodesByGroups({
81-
nodes: flow.ui.nodes,
82-
groups: ["webauthn", "passkey"],
83-
attributes: ["button"],
84-
withoutDefaultAttributes: true,
85-
withoutDefaultGroup: true,
86-
})
87-
.filter(({ attributes }) => isUiNodeInputAttributes(attributes))
88-
.map(({ attributes }) => {
89-
return (attributes as UiNodeInputAttributes).onclick
90-
})
91-
.filter((c) => c !== undefined),
9280
})
9381
})
9482
.catch(redirectOnSoftError(res, next, initFlowUrl))

views/login.hbs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<div id="login">
22
{{{card}}}
33

4-
{{> webauthn_setup nodes=nodes webAuthnHandler=webAuthnHandler webauthnTriggerName="webauthn_login_trigger"}}
54
{{> js_setup nodes=nodes}}
65
{{#if extraPartial }}
76
{{> (extraPartial) }}

views/partials/js_setup.hbs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
{{! This inserts the webauthn.js script tag}}
2+
{{#each (onlyNodes nodes "webauthn" "text/javascript")}}
3+
<script
4+
src="{{attributes.src}}"
5+
type="{{attributes.type}}"
6+
integrity="{{attributes.integrity}}"
7+
referrerpolicy="{{attributes.referrerpolicy}}"
8+
crossorigin="{{attributes.crossorigin}}"
9+
{{#if attributes.async}}async{{/if}}
10+
data-testid="node/script/{{attributes.id}}"
11+
></script>
12+
{{/each}}
113
{{! This partial sets up the onclick and onload event handlers for each passkey node.}}
214
<script type="text/javascript">
315
// register onclick and onload event handlers for each passkey node.
416
window.addEventListener("load", () => {
5-
{{#each (onlyNodes nodes "passkey" "")}}
17+
{{#each (onlyNodes nodes "passkey,webauthn" "")}}
618
{{#if attributes.onclick}}
719
// onclick for {{attributes.name}}
820
document.getElementsByName("{{attributes.name}}").forEach((el) => {

views/partials/webauthn_setup.hbs

-19
This file was deleted.

views/registration.hbs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
{{{card}}}
44

5-
{{> webauthn_setup nodes=nodes webAuthnHandler=webAuthnHandler webauthnTriggerName="webauthn_register_trigger"}}
65
{{> js_setup nodes=nodes}}
76
{{#if extraPartial }}
87
{{> (extraPartial) }}

views/settings.hbs

-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
{{{settingsScreen}}}
55
</div>
66

7-
{{> webauthn_setup nodes=nodes webAuthnHandler=webAuthnHandler webauthnTriggerName="webauthn_register_trigger"}}
87
{{> js_setup nodes=nodes}}
98
</div>

0 commit comments

Comments
 (0)