@sparkvault/sdk-js 1.27.2 → 1.27.3
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 +7 -5
- package/dist/identity/handlers/passkey-handler.d.ts +3 -3
- package/dist/identity/handlers/totp-handler.d.ts +2 -2
- package/dist/identity/index.d.ts +7 -0
- package/dist/identity/renderer.d.ts +4 -2
- package/dist/identity/state.d.ts +5 -5
- package/dist/identity/types.d.ts +37 -18
- package/dist/identity/views/method-select.d.ts +2 -2
- package/dist/identity/views/passkey-prompt.d.ts +1 -1
- package/dist/identity/views/passkey.d.ts +3 -3
- package/dist/identity/views/totp-verify.d.ts +2 -2
- package/dist/index.d.ts +25 -7
- package/dist/sparkvault.cjs.js +166 -105
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +166 -105
- 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/sparkvault.esm.js
CHANGED
|
@@ -967,12 +967,12 @@ class IdentityApi extends SparkVaultApi {
|
|
|
967
967
|
return this.configCache !== null;
|
|
968
968
|
}
|
|
969
969
|
/**
|
|
970
|
-
* Check
|
|
970
|
+
* Check whether the SVID resolved from an email or phone has registered passkeys.
|
|
971
971
|
*
|
|
972
972
|
* Returns:
|
|
973
973
|
* - identity_valid: identity passes per-type validity check
|
|
974
974
|
* (email: MX lookup; phone: E.164 format)
|
|
975
|
-
* - has_passkey: whether any passkeys are registered
|
|
975
|
+
* - has_passkey: whether any passkeys are registered on the resolved SVID
|
|
976
976
|
* (cross-tenant — single global RP)
|
|
977
977
|
*/
|
|
978
978
|
async checkPasskey(identity, identityType = 'email') {
|
|
@@ -1022,7 +1022,7 @@ class IdentityApi extends SparkVaultApi {
|
|
|
1022
1022
|
});
|
|
1023
1023
|
}
|
|
1024
1024
|
/**
|
|
1025
|
-
* Start passkey registration
|
|
1025
|
+
* Start passkey registration from a freshly verified identifier.
|
|
1026
1026
|
*/
|
|
1027
1027
|
async startPasskeyRegister(identity, identityType = 'email', registrationToken) {
|
|
1028
1028
|
const body = identityType === 'phone'
|
|
@@ -1060,19 +1060,19 @@ class IdentityApi extends SparkVaultApi {
|
|
|
1060
1060
|
});
|
|
1061
1061
|
}
|
|
1062
1062
|
/**
|
|
1063
|
-
* Start passkey verification
|
|
1063
|
+
* Start discoverable passkey verification. Legacy identity parameters are
|
|
1064
|
+
* intentionally ignored; the credential userHandle routes completion to the
|
|
1065
|
+
* SVID.
|
|
1064
1066
|
*/
|
|
1065
|
-
async startPasskeyVerify(
|
|
1066
|
-
const identityField = identityType === 'phone' ? { phone: identity } : { email: identity };
|
|
1067
|
+
async startPasskeyVerify(_identity, _identityType = 'email', authContext) {
|
|
1067
1068
|
// Backend returns { options: PublicKeyCredentialRequestOptions, session: {...} }
|
|
1068
1069
|
// Extract and flatten to match PasskeyChallengeResponse
|
|
1069
|
-
const response = await this.request('POST', '/passkey/verify',
|
|
1070
|
+
const response = await this.request('POST', '/passkey/verify', this.buildAuthContextParams(authContext));
|
|
1070
1071
|
return {
|
|
1071
1072
|
challenge: response.options.challenge,
|
|
1072
1073
|
rpId: response.options.rpId,
|
|
1073
1074
|
rpName: 'SparkVault Identity', // Not returned by verify endpoint
|
|
1074
1075
|
timeout: response.options.timeout,
|
|
1075
|
-
allowCredentials: response.options.allowCredentials,
|
|
1076
1076
|
session: response.session,
|
|
1077
1077
|
};
|
|
1078
1078
|
}
|
|
@@ -1168,7 +1168,6 @@ const METHOD_REGISTRY = {
|
|
|
1168
1168
|
passkey: {
|
|
1169
1169
|
id: 'passkey',
|
|
1170
1170
|
type: 'passkey',
|
|
1171
|
-
identityType: 'email',
|
|
1172
1171
|
name: 'Passkey',
|
|
1173
1172
|
description: 'Use biometrics or security key',
|
|
1174
1173
|
icon: 'passkey',
|
|
@@ -1313,19 +1312,20 @@ class VerificationState {
|
|
|
1313
1312
|
return this._sdkConfig?.accountId ?? '';
|
|
1314
1313
|
}
|
|
1315
1314
|
/**
|
|
1316
|
-
* Get enriched methods filtered by
|
|
1315
|
+
* Get enriched methods filtered by the fallback identifier type.
|
|
1317
1316
|
*/
|
|
1318
1317
|
getAvailableMethods() {
|
|
1319
1318
|
if (!this._sdkConfig)
|
|
1320
1319
|
return [];
|
|
1321
1320
|
const methodIds = this._sdkConfig.methods ?? [];
|
|
1322
1321
|
let methods = enrichMethods(methodIds);
|
|
1323
|
-
// Filter by
|
|
1322
|
+
// Filter by identifier type. Passkeys are SVID-scoped and remain
|
|
1323
|
+
// available regardless of whether the fallback identifier is email or phone.
|
|
1324
1324
|
if (this._identityType === 'phone') {
|
|
1325
|
-
methods = methods.filter((m) => m.type === '
|
|
1325
|
+
methods = methods.filter((m) => m.type === 'passkey' || m.identityType === 'phone');
|
|
1326
1326
|
}
|
|
1327
1327
|
else {
|
|
1328
|
-
methods = methods.filter((m) => m.identityType === 'email');
|
|
1328
|
+
methods = methods.filter((m) => m.identityType === 'email' || m.identityType === undefined);
|
|
1329
1329
|
}
|
|
1330
1330
|
return methods;
|
|
1331
1331
|
}
|
|
@@ -1355,7 +1355,9 @@ class VerificationState {
|
|
|
1355
1355
|
this._identityType = type;
|
|
1356
1356
|
}
|
|
1357
1357
|
getAllowedIdentityTypes() {
|
|
1358
|
-
|
|
1358
|
+
if (!this._sdkConfig)
|
|
1359
|
+
return ['email'];
|
|
1360
|
+
const allowed = this._sdkConfig.allowedIdentityTypes ?? ['email'];
|
|
1359
1361
|
return allowed;
|
|
1360
1362
|
}
|
|
1361
1363
|
// --- Auth Context (OIDC/simple mode) ---
|
|
@@ -1380,11 +1382,9 @@ class VerificationState {
|
|
|
1380
1382
|
}
|
|
1381
1383
|
/**
|
|
1382
1384
|
* Check if we should show passkey registration prompt
|
|
1383
|
-
* Based on: passkey enabled,
|
|
1385
|
+
* Based on: passkey enabled, the current SVID doesn't have one, not dismissed
|
|
1384
1386
|
*/
|
|
1385
1387
|
shouldShowPasskeyPrompt() {
|
|
1386
|
-
if (this._identityType !== 'email')
|
|
1387
|
-
return false;
|
|
1388
1388
|
if (!this.isPasskeyEnabled())
|
|
1389
1389
|
return false;
|
|
1390
1390
|
if (this.isPasskeyPromptDismissed())
|
|
@@ -1468,7 +1468,7 @@ class PasskeyHandler {
|
|
|
1468
1468
|
this.accountId = config.accountId;
|
|
1469
1469
|
}
|
|
1470
1470
|
/**
|
|
1471
|
-
* Check if
|
|
1471
|
+
* Check if the current identifier resolves to an SVID with registered passkeys.
|
|
1472
1472
|
* @returns Check result with emailValid and hasPasskey, or null on error
|
|
1473
1473
|
*/
|
|
1474
1474
|
async checkPasskey() {
|
|
@@ -1508,14 +1508,17 @@ class PasskeyHandler {
|
|
|
1508
1508
|
*/
|
|
1509
1509
|
async openPasskeyPopup(mode, registrationToken) {
|
|
1510
1510
|
return new Promise((resolve) => {
|
|
1511
|
-
//
|
|
1512
|
-
//
|
|
1511
|
+
// Registration carries the freshly verified identifier so the backend
|
|
1512
|
+
// can attach the credential to that SVID. Verification is discoverable:
|
|
1513
|
+
// the credential userHandle routes completion to the SVID.
|
|
1513
1514
|
const params = new URLSearchParams({
|
|
1514
1515
|
mode,
|
|
1515
1516
|
origin: window.location.origin,
|
|
1516
1517
|
});
|
|
1517
|
-
|
|
1518
|
-
|
|
1518
|
+
if (mode === 'register' && this.state.recipient) {
|
|
1519
|
+
const identityParam = this.state.identityType === 'phone' ? 'phone' : 'email';
|
|
1520
|
+
params.set(identityParam, this.state.recipient);
|
|
1521
|
+
}
|
|
1519
1522
|
// Add auth context for OIDC/simple mode flows
|
|
1520
1523
|
const authContext = this.state.authContext;
|
|
1521
1524
|
if (authContext?.authRequestId) {
|
|
@@ -1572,6 +1575,9 @@ class PasskeyHandler {
|
|
|
1572
1575
|
token: data.data.token || '',
|
|
1573
1576
|
identity: data.data.identity || this.state.recipient,
|
|
1574
1577
|
identityType: data.data.identity_type || 'email',
|
|
1578
|
+
svid: data.data.svid,
|
|
1579
|
+
sessionId: data.data.session_id,
|
|
1580
|
+
refreshToken: data.data.refresh_token,
|
|
1575
1581
|
redirect: data.data.redirect,
|
|
1576
1582
|
},
|
|
1577
1583
|
});
|
|
@@ -1675,7 +1681,7 @@ class TotpHandler {
|
|
|
1675
1681
|
this.state = state;
|
|
1676
1682
|
}
|
|
1677
1683
|
/**
|
|
1678
|
-
* Send TOTP code via email or
|
|
1684
|
+
* Send TOTP code via email, SMS, or voice
|
|
1679
1685
|
*/
|
|
1680
1686
|
async send(method) {
|
|
1681
1687
|
try {
|
|
@@ -1759,6 +1765,9 @@ class TotpHandler {
|
|
|
1759
1765
|
token: response.token,
|
|
1760
1766
|
identity: response.identity ?? this.state.recipient,
|
|
1761
1767
|
identityType: response.identity_type ?? this.state.identityType,
|
|
1768
|
+
svid: response.svid,
|
|
1769
|
+
sessionId: response.session_id,
|
|
1770
|
+
refreshToken: response.refresh_token,
|
|
1762
1771
|
redirect: response.redirect,
|
|
1763
1772
|
},
|
|
1764
1773
|
};
|
|
@@ -4099,26 +4108,33 @@ class MethodSelectView {
|
|
|
4099
4108
|
this.methodClickHandlers = new Map();
|
|
4100
4109
|
this.props = props;
|
|
4101
4110
|
// Bind handlers once for proper removal
|
|
4102
|
-
this.boundHandleBack = () => this.props.onBack();
|
|
4111
|
+
this.boundHandleBack = () => this.props.onBack?.();
|
|
4103
4112
|
}
|
|
4104
4113
|
render() {
|
|
4105
4114
|
const container = div();
|
|
4106
|
-
this.backLink = this.createBackLink();
|
|
4115
|
+
this.backLink = this.props.onBack ? this.createBackLink() : null;
|
|
4107
4116
|
const title = document.createElement('h3');
|
|
4108
4117
|
title.className = 'sv-title';
|
|
4109
4118
|
title.textContent = 'Choose how to sign in';
|
|
4110
|
-
const
|
|
4111
|
-
subtitle
|
|
4112
|
-
subtitle
|
|
4119
|
+
const email = this.props.email;
|
|
4120
|
+
const subtitle = email ? document.createElement('p') : null;
|
|
4121
|
+
if (subtitle && email) {
|
|
4122
|
+
subtitle.className = 'sv-subtitle';
|
|
4123
|
+
subtitle.textContent = escapeHtml(email);
|
|
4124
|
+
}
|
|
4113
4125
|
const methodsContainer = div();
|
|
4114
4126
|
for (const method of this.props.methods) {
|
|
4115
4127
|
const methodButton = this.createMethodButton(method);
|
|
4116
4128
|
this.methodButtons.push(methodButton);
|
|
4117
4129
|
methodsContainer.appendChild(methodButton);
|
|
4118
4130
|
}
|
|
4119
|
-
|
|
4131
|
+
if (this.backLink) {
|
|
4132
|
+
container.appendChild(this.backLink);
|
|
4133
|
+
}
|
|
4120
4134
|
container.appendChild(title);
|
|
4121
|
-
|
|
4135
|
+
if (subtitle) {
|
|
4136
|
+
container.appendChild(subtitle);
|
|
4137
|
+
}
|
|
4122
4138
|
container.appendChild(methodsContainer);
|
|
4123
4139
|
return container;
|
|
4124
4140
|
}
|
|
@@ -4179,7 +4195,7 @@ class MethodSelectView {
|
|
|
4179
4195
|
/**
|
|
4180
4196
|
* TOTP Verification View
|
|
4181
4197
|
*
|
|
4182
|
-
* Collects and validates the 6-digit TOTP code sent via email or
|
|
4198
|
+
* Collects and validates the 6-digit TOTP code sent via email, SMS, or voice.
|
|
4183
4199
|
*/
|
|
4184
4200
|
const CODE_LENGTH = 6;
|
|
4185
4201
|
class TotpVerifyView {
|
|
@@ -4503,13 +4519,13 @@ class PasskeyView {
|
|
|
4503
4519
|
this.fallbackLink = null;
|
|
4504
4520
|
this.props = props;
|
|
4505
4521
|
// Bind handlers once for proper removal
|
|
4506
|
-
this.boundHandleBack = () => this.props.onBack();
|
|
4522
|
+
this.boundHandleBack = () => this.props.onBack?.();
|
|
4507
4523
|
this.boundHandleStart = () => this.handleStart();
|
|
4508
4524
|
this.boundHandleFallback = props.onFallback ? () => props.onFallback() : null;
|
|
4509
4525
|
}
|
|
4510
4526
|
render() {
|
|
4511
4527
|
const container = div();
|
|
4512
|
-
this.backLink = this.createBackLink();
|
|
4528
|
+
this.backLink = this.props.onBack ? this.createBackLink() : null;
|
|
4513
4529
|
const iconContainer = div();
|
|
4514
4530
|
iconContainer.appendChild(createPasskeyIcon());
|
|
4515
4531
|
const title = document.createElement('h3');
|
|
@@ -4518,10 +4534,10 @@ class PasskeyView {
|
|
|
4518
4534
|
const subtitle = document.createElement('p');
|
|
4519
4535
|
subtitle.className = 'sv-subtitle';
|
|
4520
4536
|
if (this.props.mode === 'register') {
|
|
4521
|
-
subtitle.innerHTML = `Create a passkey for<br><strong>${escapeHtml(this.props.
|
|
4537
|
+
subtitle.innerHTML = `Create a passkey for<br><strong>${escapeHtml(this.props.identityLabel)}</strong><br>to sign in faster next time`;
|
|
4522
4538
|
}
|
|
4523
4539
|
else {
|
|
4524
|
-
subtitle.innerHTML =
|
|
4540
|
+
subtitle.innerHTML = 'Use a passkey linked to your SparkVault Identity';
|
|
4525
4541
|
}
|
|
4526
4542
|
this.errorContainer = div();
|
|
4527
4543
|
if (this.props.error) {
|
|
@@ -4538,7 +4554,9 @@ class PasskeyView {
|
|
|
4538
4554
|
this.actionButton.className = 'sv-btn sv-btn-primary';
|
|
4539
4555
|
this.actionButton.textContent = buttonText;
|
|
4540
4556
|
this.actionButton.addEventListener('click', this.boundHandleStart);
|
|
4541
|
-
|
|
4557
|
+
if (this.backLink) {
|
|
4558
|
+
container.appendChild(this.backLink);
|
|
4559
|
+
}
|
|
4542
4560
|
container.appendChild(iconContainer);
|
|
4543
4561
|
container.appendChild(title);
|
|
4544
4562
|
container.appendChild(subtitle);
|
|
@@ -4554,7 +4572,7 @@ class PasskeyView {
|
|
|
4554
4572
|
createFallbackLink() {
|
|
4555
4573
|
const link = document.createElement('button');
|
|
4556
4574
|
link.className = 'sv-fallback-link';
|
|
4557
|
-
link.textContent = 'Having trouble? Use
|
|
4575
|
+
link.textContent = 'Having trouble? Use a code instead';
|
|
4558
4576
|
if (this.boundHandleFallback) {
|
|
4559
4577
|
link.addEventListener('click', this.boundHandleFallback);
|
|
4560
4578
|
}
|
|
@@ -4627,7 +4645,7 @@ class PasskeyPromptView {
|
|
|
4627
4645
|
title.textContent = 'Add a passkey for faster sign-in?';
|
|
4628
4646
|
const subtitle = document.createElement('p');
|
|
4629
4647
|
subtitle.className = 'sv-subtitle';
|
|
4630
|
-
subtitle.innerHTML = `Next time, sign in instantly as<br><strong>${escapeHtml(this.props.
|
|
4648
|
+
subtitle.innerHTML = `Next time, sign in instantly as<br><strong>${escapeHtml(this.props.identityLabel)}</strong>`;
|
|
4631
4649
|
// Error message if registration failed
|
|
4632
4650
|
const errorContainer = div();
|
|
4633
4651
|
if (this.props.error) {
|
|
@@ -5320,13 +5338,7 @@ class IdentityRenderer {
|
|
|
5320
5338
|
? config.branding.backdrop_blur
|
|
5321
5339
|
: true;
|
|
5322
5340
|
this.container.updateBackdropBlur(resolvedBackdropBlur);
|
|
5323
|
-
|
|
5324
|
-
if (this.recipient) {
|
|
5325
|
-
this.showMethodSelect();
|
|
5326
|
-
}
|
|
5327
|
-
else {
|
|
5328
|
-
this.showIdentityInput();
|
|
5329
|
-
}
|
|
5341
|
+
await this.showInitialAuthStep();
|
|
5330
5342
|
}
|
|
5331
5343
|
catch (error) {
|
|
5332
5344
|
this.setState(this.viewStateForConfigError(error));
|
|
@@ -5383,12 +5395,7 @@ class IdentityRenderer {
|
|
|
5383
5395
|
? config.branding.backdrop_blur
|
|
5384
5396
|
: true;
|
|
5385
5397
|
this.container.updateBackdropBlur(resolvedBackdropBlur);
|
|
5386
|
-
|
|
5387
|
-
this.showMethodSelect();
|
|
5388
|
-
}
|
|
5389
|
-
else {
|
|
5390
|
-
this.showIdentityInput();
|
|
5391
|
-
}
|
|
5398
|
+
await this.showInitialAuthStep();
|
|
5392
5399
|
}
|
|
5393
5400
|
catch (error) {
|
|
5394
5401
|
this.setState(this.viewStateForConfigError(error));
|
|
@@ -5420,6 +5427,13 @@ class IdentityRenderer {
|
|
|
5420
5427
|
this.verificationState.setViewState(state);
|
|
5421
5428
|
this.render();
|
|
5422
5429
|
}
|
|
5430
|
+
async showInitialAuthStep() {
|
|
5431
|
+
if (this.recipient || this.getAllowedIdentityTypes().length === 0) {
|
|
5432
|
+
await this.showMethodSelect();
|
|
5433
|
+
return;
|
|
5434
|
+
}
|
|
5435
|
+
this.showIdentityInput();
|
|
5436
|
+
}
|
|
5423
5437
|
render() {
|
|
5424
5438
|
const body = this.container.getBody();
|
|
5425
5439
|
if (!body)
|
|
@@ -5468,7 +5482,7 @@ class IdentityRenderer {
|
|
|
5468
5482
|
email: state.email,
|
|
5469
5483
|
methods: state.methods,
|
|
5470
5484
|
onSelectMethod: (method) => this.handleMethodSelect(method),
|
|
5471
|
-
onBack: () => this.showIdentityInput(),
|
|
5485
|
+
onBack: state.email ? () => this.showIdentityInput() : undefined,
|
|
5472
5486
|
});
|
|
5473
5487
|
case 'totp-verify':
|
|
5474
5488
|
return new TotpVerifyView({
|
|
@@ -5485,7 +5499,7 @@ class IdentityRenderer {
|
|
|
5485
5499
|
const { passkey } = this.verificationState;
|
|
5486
5500
|
const isFromPrompt = state.mode === 'register' && passkey.pendingResult !== null;
|
|
5487
5501
|
return new PasskeyView({
|
|
5488
|
-
|
|
5502
|
+
identityLabel: state.recipient,
|
|
5489
5503
|
mode: state.mode,
|
|
5490
5504
|
error: state.error,
|
|
5491
5505
|
onStart: () => this.handlePasskeyStart(),
|
|
@@ -5493,7 +5507,11 @@ class IdentityRenderer {
|
|
|
5493
5507
|
? () => this.handlePasskeyRegistrationSkip()
|
|
5494
5508
|
: state.mode === 'verify'
|
|
5495
5509
|
// From passkey verify, enable fallback so showMethodSelect doesn't loop back
|
|
5496
|
-
?
|
|
5510
|
+
? this.passkeyFallbackMethodsAvailable()
|
|
5511
|
+
? () => this.handlePasskeyFallback()
|
|
5512
|
+
: this.recipient
|
|
5513
|
+
? () => this.showIdentityInput()
|
|
5514
|
+
: undefined
|
|
5497
5515
|
: () => this.showMethodSelect(),
|
|
5498
5516
|
onFallback: passkey.hasPasskey && !passkey.isFallbackMode
|
|
5499
5517
|
? () => this.handlePasskeyFallback()
|
|
@@ -5502,7 +5520,7 @@ class IdentityRenderer {
|
|
|
5502
5520
|
}
|
|
5503
5521
|
case 'passkey-prompt':
|
|
5504
5522
|
return new PasskeyPromptView({
|
|
5505
|
-
|
|
5523
|
+
identityLabel: state.recipient,
|
|
5506
5524
|
onAddPasskey: () => this.handlePasskeyPromptAdd(state.pendingResult),
|
|
5507
5525
|
onSkip: () => this.handlePasskeyPromptSkip(state.pendingResult),
|
|
5508
5526
|
error: state.error,
|
|
@@ -5554,45 +5572,22 @@ class IdentityRenderer {
|
|
|
5554
5572
|
}
|
|
5555
5573
|
// Enrich method IDs with metadata from static registry
|
|
5556
5574
|
let methods = enrichMethods(methodIds);
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
if (methods.length === 0) {
|
|
5567
|
-
this.setState({
|
|
5568
|
-
view: 'error',
|
|
5569
|
-
message: 'No authentication methods available',
|
|
5570
|
-
code: 'no_methods',
|
|
5575
|
+
if (this.recipient) {
|
|
5576
|
+
// Filter by identifier type. Passkeys are SVID-scoped, so they remain
|
|
5577
|
+
// available regardless of whether the fallback identifier is email or phone.
|
|
5578
|
+
methods = methods.filter((m) => {
|
|
5579
|
+
if (this.identityType === 'phone') {
|
|
5580
|
+
return m.type === 'passkey' || m.identityType === 'phone';
|
|
5581
|
+
}
|
|
5582
|
+
// Email users can use email-based methods
|
|
5583
|
+
return m.identityType === 'email' || m.identityType === undefined;
|
|
5571
5584
|
});
|
|
5572
|
-
return;
|
|
5573
5585
|
}
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5579
|
-
// Use passkey handler for the check (also validates email domain)
|
|
5580
|
-
const checkResult = await this.passkeyHandler.checkPasskey();
|
|
5581
|
-
// Handle invalid email domain
|
|
5582
|
-
if (checkResult !== null && !checkResult.emailValid) {
|
|
5583
|
-
this.showIdentityInput('This email domain cannot receive messages. Please check your email address.');
|
|
5584
|
-
return;
|
|
5585
|
-
}
|
|
5586
|
-
if (checkResult?.hasPasskey === true) {
|
|
5587
|
-
// User has passkey - go straight to passkey verification
|
|
5588
|
-
this.setState({
|
|
5589
|
-
view: 'passkey',
|
|
5590
|
-
email: this.recipient,
|
|
5591
|
-
mode: 'verify',
|
|
5592
|
-
});
|
|
5593
|
-
return;
|
|
5594
|
-
}
|
|
5595
|
-
// User doesn't have passkey - filter out passkey option
|
|
5586
|
+
else {
|
|
5587
|
+
// No PII prompt is needed when only SVID-routed methods are enabled.
|
|
5588
|
+
methods = methods.filter((m) => m.type === 'passkey' || m.type === 'social');
|
|
5589
|
+
}
|
|
5590
|
+
if (this.verificationState.passkey.isFallbackMode) {
|
|
5596
5591
|
methods = methods.filter((m) => m.type !== 'passkey');
|
|
5597
5592
|
}
|
|
5598
5593
|
if (methods.length === 0) {
|
|
@@ -5624,7 +5619,11 @@ class IdentityRenderer {
|
|
|
5624
5619
|
try {
|
|
5625
5620
|
switch (method.type) {
|
|
5626
5621
|
case 'totp': {
|
|
5627
|
-
const totpMethod = method.id === 'totp_sms'
|
|
5622
|
+
const totpMethod = method.id === 'totp_sms'
|
|
5623
|
+
? 'sms'
|
|
5624
|
+
: method.id === 'totp_voice'
|
|
5625
|
+
? 'voice'
|
|
5626
|
+
: 'email';
|
|
5628
5627
|
this.setState({ view: 'loading' });
|
|
5629
5628
|
const result = await this.totpHandler.send(totpMethod);
|
|
5630
5629
|
if (!result.success) {
|
|
@@ -5646,7 +5645,7 @@ class IdentityRenderer {
|
|
|
5646
5645
|
case 'passkey': {
|
|
5647
5646
|
this.setState({
|
|
5648
5647
|
view: 'passkey',
|
|
5649
|
-
|
|
5648
|
+
recipient: this.recipient,
|
|
5650
5649
|
mode: 'verify',
|
|
5651
5650
|
});
|
|
5652
5651
|
break;
|
|
@@ -5719,7 +5718,7 @@ class IdentityRenderer {
|
|
|
5719
5718
|
if (!result.result.redirect && await this.shouldShowPasskeyPrompt()) {
|
|
5720
5719
|
this.setState({
|
|
5721
5720
|
view: 'passkey-prompt',
|
|
5722
|
-
|
|
5721
|
+
recipient: this.recipient,
|
|
5723
5722
|
pendingResult: result.result,
|
|
5724
5723
|
});
|
|
5725
5724
|
return;
|
|
@@ -5821,7 +5820,7 @@ class IdentityRenderer {
|
|
|
5821
5820
|
if (result.errorType === 'not_found') {
|
|
5822
5821
|
this.setState({
|
|
5823
5822
|
view: 'passkey',
|
|
5824
|
-
|
|
5823
|
+
recipient: this.recipient,
|
|
5825
5824
|
mode: 'register',
|
|
5826
5825
|
error: result.error,
|
|
5827
5826
|
});
|
|
@@ -5829,7 +5828,7 @@ class IdentityRenderer {
|
|
|
5829
5828
|
else {
|
|
5830
5829
|
this.setState({
|
|
5831
5830
|
view: 'passkey',
|
|
5832
|
-
|
|
5831
|
+
recipient: this.recipient,
|
|
5833
5832
|
mode: currentMode,
|
|
5834
5833
|
error: result.error,
|
|
5835
5834
|
});
|
|
@@ -5837,13 +5836,28 @@ class IdentityRenderer {
|
|
|
5837
5836
|
}
|
|
5838
5837
|
}
|
|
5839
5838
|
/**
|
|
5840
|
-
* Handle fallback from passkey to
|
|
5841
|
-
* User clicked "Having trouble? Use
|
|
5839
|
+
* Handle fallback from passkey to an identifier-based code.
|
|
5840
|
+
* User clicked "Having trouble? Use a code instead".
|
|
5842
5841
|
*/
|
|
5843
5842
|
async handlePasskeyFallback() {
|
|
5844
5843
|
this.verificationState.enablePasskeyFallback();
|
|
5845
5844
|
await this.showMethodSelect();
|
|
5846
5845
|
}
|
|
5846
|
+
passkeyFallbackMethodsAvailable() {
|
|
5847
|
+
if (!this.sdkConfig)
|
|
5848
|
+
return false;
|
|
5849
|
+
const methods = enrichMethods(this.sdkConfig.methods ?? []);
|
|
5850
|
+
if (!this.recipient) {
|
|
5851
|
+
return methods.some((m) => m.type === 'social');
|
|
5852
|
+
}
|
|
5853
|
+
return methods.some((m) => {
|
|
5854
|
+
if (m.type === 'passkey')
|
|
5855
|
+
return false;
|
|
5856
|
+
if (this.identityType === 'phone')
|
|
5857
|
+
return m.identityType === 'phone';
|
|
5858
|
+
return m.identityType === 'email';
|
|
5859
|
+
});
|
|
5860
|
+
}
|
|
5847
5861
|
/**
|
|
5848
5862
|
* Handle skipping passkey registration when coming from passkey prompt.
|
|
5849
5863
|
* User clicked "Back" or cancelled registration after being prompted.
|
|
@@ -5921,7 +5935,7 @@ class IdentityRenderer {
|
|
|
5921
5935
|
const { passkey } = this.verificationState;
|
|
5922
5936
|
if (passkey.hasPasskey === null) {
|
|
5923
5937
|
const checkResult = await this.passkeyHandler.checkPasskey();
|
|
5924
|
-
// Only prompt if
|
|
5938
|
+
// Only prompt if the verified identifier resolves to an SVID without a passkey.
|
|
5925
5939
|
return checkResult !== null && checkResult.emailValid && !checkResult.hasPasskey;
|
|
5926
5940
|
}
|
|
5927
5941
|
return !passkey.hasPasskey;
|
|
@@ -5949,7 +5963,7 @@ class IdentityRenderer {
|
|
|
5949
5963
|
// User cancelled browser dialog - go back to prompt so they can skip or try again
|
|
5950
5964
|
this.setState({
|
|
5951
5965
|
view: 'passkey-prompt',
|
|
5952
|
-
|
|
5966
|
+
recipient: this.recipient,
|
|
5953
5967
|
pendingResult,
|
|
5954
5968
|
});
|
|
5955
5969
|
}
|
|
@@ -5958,7 +5972,7 @@ class IdentityRenderer {
|
|
|
5958
5972
|
const errorMessage = result.error || 'Failed to create passkey. Please try again.';
|
|
5959
5973
|
this.setState({
|
|
5960
5974
|
view: 'passkey-prompt',
|
|
5961
|
-
|
|
5975
|
+
recipient: this.recipient,
|
|
5962
5976
|
pendingResult,
|
|
5963
5977
|
error: errorMessage,
|
|
5964
5978
|
});
|
|
@@ -6083,6 +6097,9 @@ class IdentityRenderer {
|
|
|
6083
6097
|
token: data.token,
|
|
6084
6098
|
identity: data.identity,
|
|
6085
6099
|
identityType: data.identityType || 'email',
|
|
6100
|
+
svid: typeof data.svid === 'string' ? data.svid : undefined,
|
|
6101
|
+
sessionId: typeof data.session_id === 'string' ? data.session_id : undefined,
|
|
6102
|
+
refreshToken: typeof data.refresh_token === 'string' ? data.refresh_token : undefined,
|
|
6086
6103
|
// For simple-mode flows the server also emits a signed
|
|
6087
6104
|
// success-callback URL; without it the SDK has nowhere to send
|
|
6088
6105
|
// the user after WebSocket success.
|
|
@@ -6129,7 +6146,7 @@ class IdentityRenderer {
|
|
|
6129
6146
|
if (!result.redirect && await this.shouldShowPasskeyPrompt()) {
|
|
6130
6147
|
this.setState({
|
|
6131
6148
|
view: 'passkey-prompt',
|
|
6132
|
-
|
|
6149
|
+
recipient: this.recipient,
|
|
6133
6150
|
pendingResult: result,
|
|
6134
6151
|
});
|
|
6135
6152
|
return;
|
|
@@ -6521,6 +6538,11 @@ class IdentityModule {
|
|
|
6521
6538
|
* });
|
|
6522
6539
|
*/
|
|
6523
6540
|
async verify(options = {}) {
|
|
6541
|
+
const redirectResult = await this.consumeRedirectResult();
|
|
6542
|
+
if (redirectResult) {
|
|
6543
|
+
options.onSuccess?.(redirectResult);
|
|
6544
|
+
return redirectResult;
|
|
6545
|
+
}
|
|
6524
6546
|
if (this.renderer) {
|
|
6525
6547
|
this.renderer.close();
|
|
6526
6548
|
}
|
|
@@ -6632,8 +6654,19 @@ class IdentityModule {
|
|
|
6632
6654
|
observer?.observe(document.body, { childList: true, subtree: true });
|
|
6633
6655
|
});
|
|
6634
6656
|
};
|
|
6635
|
-
// Defer attachment until DOM is ready
|
|
6636
|
-
|
|
6657
|
+
// Defer attachment until DOM is ready, then complete any full-page
|
|
6658
|
+
// social-login redirect result before the user has to click again.
|
|
6659
|
+
onDomReady(() => {
|
|
6660
|
+
attachToElements();
|
|
6661
|
+
this.consumeRedirectResult()
|
|
6662
|
+
.then((result) => {
|
|
6663
|
+
if (result)
|
|
6664
|
+
options.onSuccess?.(result);
|
|
6665
|
+
})
|
|
6666
|
+
.catch((error) => {
|
|
6667
|
+
options.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
6668
|
+
});
|
|
6669
|
+
});
|
|
6637
6670
|
// Return cleanup function
|
|
6638
6671
|
return () => {
|
|
6639
6672
|
observer?.disconnect();
|
|
@@ -6671,6 +6704,34 @@ class IdentityModule {
|
|
|
6671
6704
|
}
|
|
6672
6705
|
return payload;
|
|
6673
6706
|
}
|
|
6707
|
+
/**
|
|
6708
|
+
* Complete full-page redirect results produced by social-login flows.
|
|
6709
|
+
* The Identity Product redirects back with `#token=...` so the token does
|
|
6710
|
+
* not hit server logs. Consume it once, validate the issuer/expiry shape,
|
|
6711
|
+
* then remove it from the URL bar.
|
|
6712
|
+
*/
|
|
6713
|
+
async consumeRedirectResult() {
|
|
6714
|
+
if (typeof window === 'undefined' || !window.location.hash) {
|
|
6715
|
+
return null;
|
|
6716
|
+
}
|
|
6717
|
+
const params = new URLSearchParams(window.location.hash.slice(1));
|
|
6718
|
+
const token = params.get('token');
|
|
6719
|
+
if (!token) {
|
|
6720
|
+
return null;
|
|
6721
|
+
}
|
|
6722
|
+
const claims = await this.verifyToken(token);
|
|
6723
|
+
const result = {
|
|
6724
|
+
token,
|
|
6725
|
+
identity: claims.identity,
|
|
6726
|
+
identityType: claims.identity_type,
|
|
6727
|
+
svid: claims.svid,
|
|
6728
|
+
sessionId: claims.session_id,
|
|
6729
|
+
};
|
|
6730
|
+
if (typeof window.history?.replaceState === 'function') {
|
|
6731
|
+
window.history.replaceState(window.history.state, document.title, `${window.location.pathname}${window.location.search}`);
|
|
6732
|
+
}
|
|
6733
|
+
return result;
|
|
6734
|
+
}
|
|
6674
6735
|
/**
|
|
6675
6736
|
* Close the identity dialog/inline UI if open.
|
|
6676
6737
|
*/
|