@sparkvault/sdk-js 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/identity/api.d.ts +11 -1
- package/dist/identity/handlers/totp-handler.d.ts +8 -0
- package/dist/identity/renderer.d.ts +19 -0
- package/dist/identity/types.d.ts +26 -0
- package/dist/identity/views/index.d.ts +1 -0
- package/dist/identity/views/two-factor.d.ts +37 -0
- package/dist/sparkvault.cjs.js +256 -24
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +256 -24
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +1 -1
package/dist/identity/api.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import type { ResolvedConfig } from '../config';
|
|
8
8
|
import { SparkVaultApi } from '../api-base';
|
|
9
9
|
import { SparkVaultError } from '../errors';
|
|
10
|
-
import type { SdkConfig, TotpSendResponse, TotpVerifyResponse, PasskeyChallengeResponse, PasskeyVerifyResponse, SparkLinkSendResponse, AuthContext } from './types';
|
|
10
|
+
import type { SdkConfig, TotpSendResponse, TotpVerifyResponse, PasskeyChallengeResponse, PasskeyVerifyResponse, SecondFactorVerifyResponse, SparkLinkSendResponse, AuthContext } from './types';
|
|
11
11
|
export declare class IdentityApi extends SparkVaultApi {
|
|
12
12
|
private readonly config;
|
|
13
13
|
/** Cached config promise - allows preloading and deduplication */
|
|
@@ -69,6 +69,16 @@ export declare class IdentityApi extends SparkVaultApi {
|
|
|
69
69
|
recipient: string;
|
|
70
70
|
authContext?: AuthContext;
|
|
71
71
|
}): Promise<TotpVerifyResponse>;
|
|
72
|
+
/**
|
|
73
|
+
* Submit a second factor (authenticator-app code or recovery code) to finish
|
|
74
|
+
* a login that the primary factor left in a `second_factor_required` state.
|
|
75
|
+
* The ticket is the opaque pending-login handle returned by the primary
|
|
76
|
+
* verify call.
|
|
77
|
+
*/
|
|
78
|
+
submitSecondFactor(params: {
|
|
79
|
+
ticket: string;
|
|
80
|
+
code: string;
|
|
81
|
+
}): Promise<SecondFactorVerifyResponse>;
|
|
72
82
|
/**
|
|
73
83
|
* Start passkey registration from a freshly verified identifier.
|
|
74
84
|
*/
|
|
@@ -31,6 +31,14 @@ export interface TotpVerifyResult {
|
|
|
31
31
|
error?: string;
|
|
32
32
|
/** Machine-readable API error code (e.g. 'identity_locked'). */
|
|
33
33
|
errorCode?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Set when the code was correct but the account has 2FA enabled — the login
|
|
36
|
+
* is not complete until a second factor is submitted against this ticket.
|
|
37
|
+
*/
|
|
38
|
+
secondFactor?: {
|
|
39
|
+
ticket: string;
|
|
40
|
+
methods: string[];
|
|
41
|
+
};
|
|
34
42
|
}
|
|
35
43
|
/**
|
|
36
44
|
* Handles TOTP code sending and verification
|
|
@@ -86,10 +86,29 @@ export declare class IdentityRenderer {
|
|
|
86
86
|
private showMethodSelect;
|
|
87
87
|
private handleIdentitySubmit;
|
|
88
88
|
private getAllowedIdentityTypes;
|
|
89
|
+
/**
|
|
90
|
+
* @param userInitiated True when called from a live click on the picker, so
|
|
91
|
+
* a popup may be opened synchronously within that gesture. False when
|
|
92
|
+
* auto-selected after an async step (e.g. the single enabled method), where
|
|
93
|
+
* opening a popup would be blocked.
|
|
94
|
+
*/
|
|
89
95
|
private handleMethodSelect;
|
|
90
96
|
private handleTotpSubmit;
|
|
97
|
+
private handleSecondFactorSubmit;
|
|
91
98
|
private handleTotpResend;
|
|
92
99
|
private handlePasskeyStart;
|
|
100
|
+
/**
|
|
101
|
+
* Open the verify popup straight from a live picker gesture, showing a
|
|
102
|
+
* loading state while the ceremony runs. window.open inside verify() fires
|
|
103
|
+
* synchronously (before the first await), so it stays within the gesture.
|
|
104
|
+
*/
|
|
105
|
+
private launchPasskeyVerify;
|
|
106
|
+
/**
|
|
107
|
+
* Apply a passkey ceremony result: complete on success, or route to the
|
|
108
|
+
* matching recovery state. Shared by the passkey view and the direct
|
|
109
|
+
* picker launch so both behave identically.
|
|
110
|
+
*/
|
|
111
|
+
private applyPasskeyResult;
|
|
93
112
|
/**
|
|
94
113
|
* Handle fallback from passkey to an identifier-based code.
|
|
95
114
|
* User clicked "Having trouble? Use a code instead".
|
package/dist/identity/types.d.ts
CHANGED
|
@@ -168,6 +168,12 @@ export interface TotpVerifyResponse {
|
|
|
168
168
|
retry_after?: number;
|
|
169
169
|
/** Returned on failure - when the backoff expires */
|
|
170
170
|
expires_at?: number;
|
|
171
|
+
/** Set when the primary factor succeeded but 2FA is still owed */
|
|
172
|
+
second_factor_required?: boolean;
|
|
173
|
+
/** Opaque pending-login handle to submit the second factor against */
|
|
174
|
+
ticket?: string;
|
|
175
|
+
/** Second-factor methods the user can use, e.g. ['authenticator','recovery_code'] */
|
|
176
|
+
methods?: string[];
|
|
171
177
|
}
|
|
172
178
|
export interface PasskeyChallengeResponse {
|
|
173
179
|
challenge: string;
|
|
@@ -192,6 +198,21 @@ export interface PasskeyVerifyResponse {
|
|
|
192
198
|
/** Redirect URL for OIDC/simple mode flows */
|
|
193
199
|
redirect?: string;
|
|
194
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Result of completing a login via the second factor. On success this is the
|
|
203
|
+
* same shape as any verified login; a wrong code surfaces as a thrown error.
|
|
204
|
+
*/
|
|
205
|
+
export interface SecondFactorVerifyResponse {
|
|
206
|
+
verified?: boolean;
|
|
207
|
+
token?: string;
|
|
208
|
+
identity?: string;
|
|
209
|
+
identity_type?: VerifiedIdentityType;
|
|
210
|
+
svid?: string;
|
|
211
|
+
session_id?: string;
|
|
212
|
+
refresh_token?: string;
|
|
213
|
+
/** Redirect URL the caller should navigate to. */
|
|
214
|
+
redirect?: string;
|
|
215
|
+
}
|
|
195
216
|
export interface SparkLinkSendResponse {
|
|
196
217
|
sparkId: string;
|
|
197
218
|
expiresAt: number;
|
|
@@ -212,6 +233,11 @@ export type IdentityViewState = {
|
|
|
212
233
|
kindling: string;
|
|
213
234
|
error?: string;
|
|
214
235
|
backoffExpires?: number;
|
|
236
|
+
} | {
|
|
237
|
+
view: 'two-factor';
|
|
238
|
+
ticket: string;
|
|
239
|
+
methods: string[];
|
|
240
|
+
error?: string;
|
|
215
241
|
} | {
|
|
216
242
|
view: 'passkey';
|
|
217
243
|
recipient: string;
|
|
@@ -8,6 +8,7 @@ export * from './loading';
|
|
|
8
8
|
export * from './identity-input';
|
|
9
9
|
export * from './method-select';
|
|
10
10
|
export * from './totp-verify';
|
|
11
|
+
export * from './two-factor';
|
|
11
12
|
export * from './passkey';
|
|
12
13
|
export * from './passkey-prompt';
|
|
13
14
|
export * from './sparklink-waiting';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two-Factor View
|
|
3
|
+
*
|
|
4
|
+
* Shown after a primary factor succeeds for an account with 2FA enabled.
|
|
5
|
+
* Collects a 6-digit authenticator-app code, or (if offered) a recovery code,
|
|
6
|
+
* and submits it to complete the login.
|
|
7
|
+
*/
|
|
8
|
+
import type { View } from './base';
|
|
9
|
+
export interface TwoFactorViewProps {
|
|
10
|
+
/** Second-factor methods the server offers, e.g. ['authenticator','recovery_code']. */
|
|
11
|
+
methods: string[];
|
|
12
|
+
error?: string;
|
|
13
|
+
onSubmit: (code: string) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare class TwoFactorView implements View {
|
|
16
|
+
private readonly props;
|
|
17
|
+
private input;
|
|
18
|
+
private submitButton;
|
|
19
|
+
private toggleButton;
|
|
20
|
+
private errorContainer;
|
|
21
|
+
private promptEl;
|
|
22
|
+
private recoveryMode;
|
|
23
|
+
private isSubmitting;
|
|
24
|
+
private focusTimeoutId;
|
|
25
|
+
private readonly boundSubmit;
|
|
26
|
+
private readonly boundToggle;
|
|
27
|
+
private readonly boundKeydown;
|
|
28
|
+
private readonly boundInput;
|
|
29
|
+
constructor(props: TwoFactorViewProps);
|
|
30
|
+
render(): HTMLElement;
|
|
31
|
+
private toggleRecovery;
|
|
32
|
+
private clearError;
|
|
33
|
+
/** Surface a server-side error and re-enable the form for another attempt. */
|
|
34
|
+
showError(message: string): void;
|
|
35
|
+
private handleSubmit;
|
|
36
|
+
destroy(): void;
|
|
37
|
+
}
|
package/dist/sparkvault.cjs.js
CHANGED
|
@@ -1068,6 +1068,18 @@ class IdentityApi extends SparkVaultApi {
|
|
|
1068
1068
|
...this.buildAuthContextParams(params.authContext),
|
|
1069
1069
|
});
|
|
1070
1070
|
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Submit a second factor (authenticator-app code or recovery code) to finish
|
|
1073
|
+
* a login that the primary factor left in a `second_factor_required` state.
|
|
1074
|
+
* The ticket is the opaque pending-login handle returned by the primary
|
|
1075
|
+
* verify call.
|
|
1076
|
+
*/
|
|
1077
|
+
async submitSecondFactor(params) {
|
|
1078
|
+
return this.request('POST', '/second-factor/verify', {
|
|
1079
|
+
ticket: params.ticket,
|
|
1080
|
+
code: params.code,
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1071
1083
|
/**
|
|
1072
1084
|
* Start passkey registration from a freshly verified identifier.
|
|
1073
1085
|
*/
|
|
@@ -1812,6 +1824,14 @@ class TotpHandler {
|
|
|
1812
1824
|
recipient: this.state.recipient,
|
|
1813
1825
|
authContext: this.state.authContext,
|
|
1814
1826
|
});
|
|
1827
|
+
// Primary factor accepted, but the account requires a second factor.
|
|
1828
|
+
// Not a success and not a retry — hand the ticket up to drive the 2FA step.
|
|
1829
|
+
if (response.second_factor_required && response.ticket) {
|
|
1830
|
+
return {
|
|
1831
|
+
success: false,
|
|
1832
|
+
secondFactor: { ticket: response.ticket, methods: response.methods ?? ['authenticator'] },
|
|
1833
|
+
};
|
|
1834
|
+
}
|
|
1815
1835
|
if (response.verified && (response.token || response.redirect)) {
|
|
1816
1836
|
return {
|
|
1817
1837
|
success: true,
|
|
@@ -4560,6 +4580,144 @@ class TotpVerifyView {
|
|
|
4560
4580
|
}
|
|
4561
4581
|
}
|
|
4562
4582
|
|
|
4583
|
+
/**
|
|
4584
|
+
* Two-Factor View
|
|
4585
|
+
*
|
|
4586
|
+
* Shown after a primary factor succeeds for an account with 2FA enabled.
|
|
4587
|
+
* Collects a 6-digit authenticator-app code, or (if offered) a recovery code,
|
|
4588
|
+
* and submits it to complete the login.
|
|
4589
|
+
*/
|
|
4590
|
+
class TwoFactorView {
|
|
4591
|
+
constructor(props) {
|
|
4592
|
+
this.input = null;
|
|
4593
|
+
this.submitButton = null;
|
|
4594
|
+
this.toggleButton = null;
|
|
4595
|
+
this.errorContainer = null;
|
|
4596
|
+
this.promptEl = null;
|
|
4597
|
+
this.recoveryMode = false;
|
|
4598
|
+
this.isSubmitting = false;
|
|
4599
|
+
this.focusTimeoutId = null;
|
|
4600
|
+
this.props = props;
|
|
4601
|
+
this.boundSubmit = () => this.handleSubmit();
|
|
4602
|
+
this.boundToggle = () => this.toggleRecovery();
|
|
4603
|
+
this.boundKeydown = (e) => { if (e.key === 'Enter')
|
|
4604
|
+
this.handleSubmit(); };
|
|
4605
|
+
this.boundInput = () => this.clearError();
|
|
4606
|
+
}
|
|
4607
|
+
render() {
|
|
4608
|
+
const container = div();
|
|
4609
|
+
container.style.display = 'flex';
|
|
4610
|
+
container.style.flexDirection = 'column';
|
|
4611
|
+
const title = document.createElement('h3');
|
|
4612
|
+
title.className = 'sv-title';
|
|
4613
|
+
title.textContent = 'Two-step verification';
|
|
4614
|
+
this.promptEl = document.createElement('p');
|
|
4615
|
+
this.promptEl.className = 'sv-subtitle';
|
|
4616
|
+
this.promptEl.innerHTML = 'Enter the 6-digit code from your authenticator app.';
|
|
4617
|
+
this.errorContainer = div();
|
|
4618
|
+
if (this.props.error) {
|
|
4619
|
+
this.errorContainer.appendChild(errorMessage(this.props.error));
|
|
4620
|
+
}
|
|
4621
|
+
this.input = document.createElement('input');
|
|
4622
|
+
this.input.type = 'text';
|
|
4623
|
+
this.input.inputMode = 'numeric';
|
|
4624
|
+
this.input.autocomplete = 'one-time-code';
|
|
4625
|
+
this.input.maxLength = 6;
|
|
4626
|
+
this.input.className = 'sv-input';
|
|
4627
|
+
this.input.setAttribute('aria-label', 'Verification code');
|
|
4628
|
+
this.input.placeholder = '000000';
|
|
4629
|
+
this.input.addEventListener('keydown', this.boundKeydown);
|
|
4630
|
+
this.input.addEventListener('input', this.boundInput);
|
|
4631
|
+
this.submitButton = document.createElement('button');
|
|
4632
|
+
this.submitButton.className = 'sv-btn sv-btn-primary';
|
|
4633
|
+
this.submitButton.textContent = 'Verify';
|
|
4634
|
+
this.submitButton.addEventListener('click', this.boundSubmit);
|
|
4635
|
+
container.appendChild(title);
|
|
4636
|
+
container.appendChild(this.promptEl);
|
|
4637
|
+
container.appendChild(this.errorContainer);
|
|
4638
|
+
container.appendChild(this.input);
|
|
4639
|
+
container.appendChild(this.submitButton);
|
|
4640
|
+
if (this.props.methods?.includes('recovery_code')) {
|
|
4641
|
+
this.toggleButton = document.createElement('button');
|
|
4642
|
+
this.toggleButton.className = 'sv-back-link';
|
|
4643
|
+
this.toggleButton.textContent = 'Use a recovery code instead';
|
|
4644
|
+
this.toggleButton.addEventListener('click', this.boundToggle);
|
|
4645
|
+
container.appendChild(this.toggleButton);
|
|
4646
|
+
}
|
|
4647
|
+
this.focusTimeoutId = setTimeout(() => this.input?.focus(), 50);
|
|
4648
|
+
return container;
|
|
4649
|
+
}
|
|
4650
|
+
toggleRecovery() {
|
|
4651
|
+
if (!this.input || !this.promptEl || !this.toggleButton)
|
|
4652
|
+
return;
|
|
4653
|
+
this.recoveryMode = !this.recoveryMode;
|
|
4654
|
+
this.input.value = '';
|
|
4655
|
+
this.clearError();
|
|
4656
|
+
if (this.recoveryMode) {
|
|
4657
|
+
this.input.inputMode = 'text';
|
|
4658
|
+
this.input.removeAttribute('maxlength');
|
|
4659
|
+
this.input.placeholder = 'XXXX-XXXX-XXXX-XXXX';
|
|
4660
|
+
this.promptEl.innerHTML = 'Enter one of your recovery codes.';
|
|
4661
|
+
this.toggleButton.textContent = 'Use your authenticator app instead';
|
|
4662
|
+
}
|
|
4663
|
+
else {
|
|
4664
|
+
this.input.inputMode = 'numeric';
|
|
4665
|
+
this.input.maxLength = 6;
|
|
4666
|
+
this.input.placeholder = '000000';
|
|
4667
|
+
this.promptEl.innerHTML = 'Enter the 6-digit code from your authenticator app.';
|
|
4668
|
+
this.toggleButton.textContent = 'Use a recovery code instead';
|
|
4669
|
+
}
|
|
4670
|
+
this.input.focus();
|
|
4671
|
+
}
|
|
4672
|
+
clearError() {
|
|
4673
|
+
if (this.errorContainer)
|
|
4674
|
+
clearChildren(this.errorContainer);
|
|
4675
|
+
this.input?.classList.remove('sv-input-error');
|
|
4676
|
+
}
|
|
4677
|
+
/** Surface a server-side error and re-enable the form for another attempt. */
|
|
4678
|
+
showError(message) {
|
|
4679
|
+
if (this.errorContainer) {
|
|
4680
|
+
clearChildren(this.errorContainer);
|
|
4681
|
+
this.errorContainer.appendChild(errorMessage(message));
|
|
4682
|
+
}
|
|
4683
|
+
this.input?.classList.add('sv-input-error');
|
|
4684
|
+
this.isSubmitting = false;
|
|
4685
|
+
if (this.submitButton) {
|
|
4686
|
+
this.submitButton.disabled = false;
|
|
4687
|
+
this.submitButton.textContent = 'Verify';
|
|
4688
|
+
}
|
|
4689
|
+
this.input?.focus();
|
|
4690
|
+
this.input?.select();
|
|
4691
|
+
}
|
|
4692
|
+
handleSubmit() {
|
|
4693
|
+
if (this.isSubmitting || !this.submitButton || !this.input)
|
|
4694
|
+
return;
|
|
4695
|
+
const code = this.input.value.trim();
|
|
4696
|
+
if (!code) {
|
|
4697
|
+
this.showError(this.recoveryMode ? 'Enter a recovery code' : 'Enter the 6-digit code');
|
|
4698
|
+
return;
|
|
4699
|
+
}
|
|
4700
|
+
if (!this.recoveryMode && !/^\d{6}$/.test(code)) {
|
|
4701
|
+
this.showError('Enter the complete 6-digit code');
|
|
4702
|
+
return;
|
|
4703
|
+
}
|
|
4704
|
+
this.isSubmitting = true;
|
|
4705
|
+
this.submitButton.disabled = true;
|
|
4706
|
+
this.submitButton.textContent = 'Verifying...';
|
|
4707
|
+
this.props.onSubmit(code);
|
|
4708
|
+
}
|
|
4709
|
+
destroy() {
|
|
4710
|
+
if (this.focusTimeoutId !== null) {
|
|
4711
|
+
clearTimeout(this.focusTimeoutId);
|
|
4712
|
+
this.focusTimeoutId = null;
|
|
4713
|
+
}
|
|
4714
|
+
this.input?.removeEventListener('keydown', this.boundKeydown);
|
|
4715
|
+
this.input?.removeEventListener('input', this.boundInput);
|
|
4716
|
+
this.submitButton?.removeEventListener('click', this.boundSubmit);
|
|
4717
|
+
this.toggleButton?.removeEventListener('click', this.boundToggle);
|
|
4718
|
+
}
|
|
4719
|
+
}
|
|
4720
|
+
|
|
4563
4721
|
/**
|
|
4564
4722
|
* Passkey View
|
|
4565
4723
|
*
|
|
@@ -5715,7 +5873,7 @@ class IdentityRenderer {
|
|
|
5715
5873
|
return new MethodSelectView({
|
|
5716
5874
|
email: state.email,
|
|
5717
5875
|
methods: state.methods,
|
|
5718
|
-
onSelectMethod: (method) => this.handleMethodSelect(method),
|
|
5876
|
+
onSelectMethod: (method) => this.handleMethodSelect(method, true),
|
|
5719
5877
|
onBack: state.email ? () => this.showIdentityInput() : undefined,
|
|
5720
5878
|
});
|
|
5721
5879
|
case 'totp-verify':
|
|
@@ -5728,6 +5886,12 @@ class IdentityRenderer {
|
|
|
5728
5886
|
onResend: () => this.handleTotpResend(),
|
|
5729
5887
|
onBack: () => this.showMethodSelect(),
|
|
5730
5888
|
});
|
|
5889
|
+
case 'two-factor':
|
|
5890
|
+
return new TwoFactorView({
|
|
5891
|
+
methods: state.methods,
|
|
5892
|
+
error: state.error,
|
|
5893
|
+
onSubmit: (code) => this.handleSecondFactorSubmit(code),
|
|
5894
|
+
});
|
|
5731
5895
|
case 'passkey': {
|
|
5732
5896
|
// If coming from passkey prompt with a pending result, "back" should skip registration
|
|
5733
5897
|
const { passkey } = this.verificationState;
|
|
@@ -5888,7 +6052,13 @@ class IdentityRenderer {
|
|
|
5888
6052
|
getAllowedIdentityTypes() {
|
|
5889
6053
|
return this.verificationState.getAllowedIdentityTypes();
|
|
5890
6054
|
}
|
|
5891
|
-
|
|
6055
|
+
/**
|
|
6056
|
+
* @param userInitiated True when called from a live click on the picker, so
|
|
6057
|
+
* a popup may be opened synchronously within that gesture. False when
|
|
6058
|
+
* auto-selected after an async step (e.g. the single enabled method), where
|
|
6059
|
+
* opening a popup would be blocked.
|
|
6060
|
+
*/
|
|
6061
|
+
async handleMethodSelect(method, userInitiated = false) {
|
|
5892
6062
|
try {
|
|
5893
6063
|
switch (method.type) {
|
|
5894
6064
|
case 'totp': {
|
|
@@ -5916,11 +6086,21 @@ class IdentityRenderer {
|
|
|
5916
6086
|
break;
|
|
5917
6087
|
}
|
|
5918
6088
|
case 'passkey': {
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
6089
|
+
if (userInitiated) {
|
|
6090
|
+
// Live picker tap: open the passkey popup directly within this
|
|
6091
|
+
// gesture (window.open in verify() runs before the first await),
|
|
6092
|
+
// skipping the redundant in-widget passkey screen.
|
|
6093
|
+
await this.launchPasskeyVerify();
|
|
6094
|
+
}
|
|
6095
|
+
else {
|
|
6096
|
+
// Auto-selected without a fresh gesture: a popup would be blocked,
|
|
6097
|
+
// so land on the passkey view whose button supplies the gesture.
|
|
6098
|
+
this.setState({
|
|
6099
|
+
view: 'passkey',
|
|
6100
|
+
recipient: this.recipient,
|
|
6101
|
+
mode: 'verify',
|
|
6102
|
+
});
|
|
6103
|
+
}
|
|
5924
6104
|
break;
|
|
5925
6105
|
}
|
|
5926
6106
|
case 'sparklink': {
|
|
@@ -5985,6 +6165,14 @@ class IdentityRenderer {
|
|
|
5985
6165
|
return;
|
|
5986
6166
|
const currentMethod = this.verificationState.totp.method ?? 'email';
|
|
5987
6167
|
const result = await this.totpHandler.verify(code);
|
|
6168
|
+
if (result.secondFactor) {
|
|
6169
|
+
this.setState({
|
|
6170
|
+
view: 'two-factor',
|
|
6171
|
+
ticket: result.secondFactor.ticket,
|
|
6172
|
+
methods: result.secondFactor.methods,
|
|
6173
|
+
});
|
|
6174
|
+
return;
|
|
6175
|
+
}
|
|
5988
6176
|
if (result.success && result.result) {
|
|
5989
6177
|
// Passkey upsell only when there's no redirect target — with one,
|
|
5990
6178
|
// we head to the destination immediately.
|
|
@@ -6050,6 +6238,34 @@ class IdentityRenderer {
|
|
|
6050
6238
|
});
|
|
6051
6239
|
}
|
|
6052
6240
|
}
|
|
6241
|
+
async handleSecondFactorSubmit(code) {
|
|
6242
|
+
if (this.viewState.view !== 'two-factor')
|
|
6243
|
+
return;
|
|
6244
|
+
const { ticket, methods } = this.viewState;
|
|
6245
|
+
try {
|
|
6246
|
+
const response = await this.api.submitSecondFactor({ ticket, code });
|
|
6247
|
+
const result = {
|
|
6248
|
+
token: response.token ?? '',
|
|
6249
|
+
identity: response.identity ?? this.recipient,
|
|
6250
|
+
identityType: response.identity_type ?? this.identityType,
|
|
6251
|
+
svid: response.svid,
|
|
6252
|
+
sessionId: response.session_id,
|
|
6253
|
+
refreshToken: response.refresh_token,
|
|
6254
|
+
redirect: response.redirect,
|
|
6255
|
+
};
|
|
6256
|
+
this.close();
|
|
6257
|
+
this.safeOnSuccess(result);
|
|
6258
|
+
if (typeof result.redirect === 'string' && result.redirect) {
|
|
6259
|
+
window.location.href = result.redirect;
|
|
6260
|
+
}
|
|
6261
|
+
}
|
|
6262
|
+
catch (error) {
|
|
6263
|
+
const message = error instanceof Error ? error.message : 'That code is not valid. Please try again.';
|
|
6264
|
+
// The login ticket is not consumed on a wrong code, so the user can retry
|
|
6265
|
+
// against the same ticket — re-render the view carrying the error.
|
|
6266
|
+
this.setState({ view: 'two-factor', ticket, methods, error: message });
|
|
6267
|
+
}
|
|
6268
|
+
}
|
|
6053
6269
|
async handleTotpResend() {
|
|
6054
6270
|
if (this.viewState.view !== 'totp-verify')
|
|
6055
6271
|
return;
|
|
@@ -6073,6 +6289,24 @@ class IdentityRenderer {
|
|
|
6073
6289
|
const result = currentMode === 'register'
|
|
6074
6290
|
? await this.passkeyHandler.register()
|
|
6075
6291
|
: await this.passkeyHandler.verify();
|
|
6292
|
+
this.applyPasskeyResult(result, currentMode);
|
|
6293
|
+
}
|
|
6294
|
+
/**
|
|
6295
|
+
* Open the verify popup straight from a live picker gesture, showing a
|
|
6296
|
+
* loading state while the ceremony runs. window.open inside verify() fires
|
|
6297
|
+
* synchronously (before the first await), so it stays within the gesture.
|
|
6298
|
+
*/
|
|
6299
|
+
async launchPasskeyVerify() {
|
|
6300
|
+
this.setState({ view: 'loading' });
|
|
6301
|
+
const result = await this.passkeyHandler.verify();
|
|
6302
|
+
this.applyPasskeyResult(result, 'verify');
|
|
6303
|
+
}
|
|
6304
|
+
/**
|
|
6305
|
+
* Apply a passkey ceremony result: complete on success, or route to the
|
|
6306
|
+
* matching recovery state. Shared by the passkey view and the direct
|
|
6307
|
+
* picker launch so both behave identically.
|
|
6308
|
+
*/
|
|
6309
|
+
applyPasskeyResult(result, currentMode) {
|
|
6076
6310
|
if (result.success && result.result) {
|
|
6077
6311
|
this.close();
|
|
6078
6312
|
this.safeOnSuccess(result.result);
|
|
@@ -6088,24 +6322,22 @@ class IdentityRenderer {
|
|
|
6088
6322
|
message: 'This SparkVault Identity is locked. Visit auth.sv to manage it.',
|
|
6089
6323
|
});
|
|
6090
6324
|
}
|
|
6325
|
+
else if (result.errorType === 'not_found') {
|
|
6326
|
+
// No passkey yet — pivot the same screen to registration.
|
|
6327
|
+
this.setState({
|
|
6328
|
+
view: 'passkey',
|
|
6329
|
+
recipient: this.recipient,
|
|
6330
|
+
mode: 'register',
|
|
6331
|
+
error: result.error,
|
|
6332
|
+
});
|
|
6333
|
+
}
|
|
6091
6334
|
else {
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
this.
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
error: result.error,
|
|
6099
|
-
});
|
|
6100
|
-
}
|
|
6101
|
-
else {
|
|
6102
|
-
this.setState({
|
|
6103
|
-
view: 'passkey',
|
|
6104
|
-
recipient: this.recipient,
|
|
6105
|
-
mode: currentMode,
|
|
6106
|
-
error: result.error,
|
|
6107
|
-
});
|
|
6108
|
-
}
|
|
6335
|
+
this.setState({
|
|
6336
|
+
view: 'passkey',
|
|
6337
|
+
recipient: this.recipient,
|
|
6338
|
+
mode: currentMode,
|
|
6339
|
+
error: result.error,
|
|
6340
|
+
});
|
|
6109
6341
|
}
|
|
6110
6342
|
}
|
|
6111
6343
|
/**
|