Skip to content

Commit 131ebfe

Browse files
committed
New events
1 parent 5edd73f commit 131ebfe

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

src/stimulus/Resources/assets/dist/controller.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,23 @@ class default_1 extends Controller {
1616
async signin(event) {
1717
event.preventDefault();
1818
const data = this._getData();
19+
const optionsHeaders = {
20+
'Content-Type': 'application/json',
21+
};
22+
this._dispatchEvent('webauthn:request:options', { data, headers: optionsHeaders });
1923
const resp = await fetch(this.requestOptionsUrlValue || '/request/options', {
2024
method: 'POST',
21-
headers: {
22-
'Content-Type': 'application/json',
23-
},
25+
headers: optionsHeaders,
2426
body: JSON.stringify(data),
2527
});
2628
const asseResp = await startAuthentication(await resp.json());
29+
const responseHeaders = {
30+
'Content-Type': 'application/json',
31+
};
32+
this._dispatchEvent('webauthn:request:response', { response: asseResp, headers: responseHeaders });
2733
const verificationResp = await fetch(this.requestResultUrlValue || '/request', {
2834
method: 'POST',
29-
headers: {
30-
'Content-Type': 'application/json',
31-
},
35+
headers: responseHeaders,
3236
body: JSON.stringify(asseResp),
3337
});
3438
const verificationJSON = await verificationResp.json();
@@ -46,19 +50,23 @@ class default_1 extends Controller {
4650
async signup(event) {
4751
event.preventDefault();
4852
const data = this._getData();
53+
const optionsHeaders = {
54+
'Content-Type': 'application/json',
55+
};
56+
this._dispatchEvent('webauthn:creation:options', { data, headers: optionsHeaders });
4957
const resp = await fetch(this.creationOptionsUrlValue || '/creation/options', {
5058
method: 'POST',
51-
headers: {
52-
'Content-Type': 'application/json',
53-
},
59+
headers: optionsHeaders,
5460
body: JSON.stringify(data),
5561
});
5662
const attResp = await startRegistration(await resp.json());
63+
const responseHeaders = {
64+
'Content-Type': 'application/json',
65+
};
66+
this._dispatchEvent('webauthn:creation:response', { response: attResp, headers: responseHeaders });
5767
const verificationResp = await fetch(this.creationResultUrlValue || '/creation', {
5868
method: 'POST',
59-
headers: {
60-
'Content-Type': 'application/json',
61-
},
69+
headers: responseHeaders,
6270
body: JSON.stringify(attResp),
6371
});
6472
const verificationJSON = await verificationResp.json();

src/stimulus/Resources/assets/src/controller.ts

+20-12
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,25 @@ export default class extends Controller {
2929
async signin(event: Event) {
3030
event.preventDefault();
3131
const data = this._getData();
32+
const optionsHeaders = {
33+
'Content-Type': 'application/json',
34+
};
35+
this._dispatchEvent('webauthn:request:options', { data, headers: optionsHeaders });
3236
const resp = await fetch(this.requestOptionsUrlValue || '/request/options', {
3337
method: 'POST',
34-
headers: {
35-
'Content-Type': 'application/json',
36-
},
38+
headers: optionsHeaders,
3739
body: JSON.stringify(data),
3840
});
3941

4042
const asseResp = await startAuthentication(await resp.json());
4143

44+
const responseHeaders = {
45+
'Content-Type': 'application/json',
46+
};
47+
this._dispatchEvent('webauthn:request:response', { response: asseResp, headers: responseHeaders });
4248
const verificationResp = await fetch(this.requestResultUrlValue || '/request', {
4349
method: 'POST',
44-
headers: {
45-
'Content-Type': 'application/json',
46-
},
50+
headers: responseHeaders,
4751
body: JSON.stringify(asseResp),
4852
});
4953

@@ -62,20 +66,24 @@ export default class extends Controller {
6266
async signup(event: Event) {
6367
event.preventDefault();
6468
const data = this._getData();
69+
const optionsHeaders = {
70+
'Content-Type': 'application/json',
71+
};
72+
this._dispatchEvent('webauthn:creation:options', { data, headers: optionsHeaders });
6573
const resp = await fetch(this.creationOptionsUrlValue || '/creation/options', {
6674
method: 'POST',
67-
headers: {
68-
'Content-Type': 'application/json',
69-
},
75+
headers: optionsHeaders,
7076
body: JSON.stringify(data),
7177
});
7278

7379
const attResp = await startRegistration(await resp.json());
80+
const responseHeaders = {
81+
'Content-Type': 'application/json',
82+
};
83+
this._dispatchEvent('webauthn:creation:response', { response: attResp, headers: responseHeaders });
7484
const verificationResp = await fetch(this.creationResultUrlValue || '/creation', {
7585
method: 'POST',
76-
headers: {
77-
'Content-Type': 'application/json',
78-
},
86+
headers: responseHeaders,
7987
body: JSON.stringify(attResp),
8088
});
8189

0 commit comments

Comments
 (0)