@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.
@@ -971,12 +971,12 @@ class IdentityApi extends SparkVaultApi {
971
971
  return this.configCache !== null;
972
972
  }
973
973
  /**
974
- * Check if an identity (email or phone) has registered passkeys.
974
+ * Check whether the SVID resolved from an email or phone has registered passkeys.
975
975
  *
976
976
  * Returns:
977
977
  * - identity_valid: identity passes per-type validity check
978
978
  * (email: MX lookup; phone: E.164 format)
979
- * - has_passkey: whether any passkeys are registered for this identity
979
+ * - has_passkey: whether any passkeys are registered on the resolved SVID
980
980
  * (cross-tenant — single global RP)
981
981
  */
982
982
  async checkPasskey(identity, identityType = 'email') {
@@ -1026,7 +1026,7 @@ class IdentityApi extends SparkVaultApi {
1026
1026
  });
1027
1027
  }
1028
1028
  /**
1029
- * Start passkey registration for an identity (email or phone).
1029
+ * Start passkey registration from a freshly verified identifier.
1030
1030
  */
1031
1031
  async startPasskeyRegister(identity, identityType = 'email', registrationToken) {
1032
1032
  const body = identityType === 'phone'
@@ -1064,19 +1064,19 @@ class IdentityApi extends SparkVaultApi {
1064
1064
  });
1065
1065
  }
1066
1066
  /**
1067
- * Start passkey verification for an identity (email or phone).
1067
+ * Start discoverable passkey verification. Legacy identity parameters are
1068
+ * intentionally ignored; the credential userHandle routes completion to the
1069
+ * SVID.
1068
1070
  */
1069
- async startPasskeyVerify(identity, identityType = 'email', authContext) {
1070
- const identityField = identityType === 'phone' ? { phone: identity } : { email: identity };
1071
+ async startPasskeyVerify(_identity, _identityType = 'email', authContext) {
1071
1072
  // Backend returns { options: PublicKeyCredentialRequestOptions, session: {...} }
1072
1073
  // Extract and flatten to match PasskeyChallengeResponse
1073
- const response = await this.request('POST', '/passkey/verify', { ...identityField, ...this.buildAuthContextParams(authContext) });
1074
+ const response = await this.request('POST', '/passkey/verify', this.buildAuthContextParams(authContext));
1074
1075
  return {
1075
1076
  challenge: response.options.challenge,
1076
1077
  rpId: response.options.rpId,
1077
1078
  rpName: 'SparkVault Identity', // Not returned by verify endpoint
1078
1079
  timeout: response.options.timeout,
1079
- allowCredentials: response.options.allowCredentials,
1080
1080
  session: response.session,
1081
1081
  };
1082
1082
  }
@@ -1172,7 +1172,6 @@ const METHOD_REGISTRY = {
1172
1172
  passkey: {
1173
1173
  id: 'passkey',
1174
1174
  type: 'passkey',
1175
- identityType: 'email',
1176
1175
  name: 'Passkey',
1177
1176
  description: 'Use biometrics or security key',
1178
1177
  icon: 'passkey',
@@ -1317,19 +1316,20 @@ class VerificationState {
1317
1316
  return this._sdkConfig?.accountId ?? '';
1318
1317
  }
1319
1318
  /**
1320
- * Get enriched methods filtered by identity type
1319
+ * Get enriched methods filtered by the fallback identifier type.
1321
1320
  */
1322
1321
  getAvailableMethods() {
1323
1322
  if (!this._sdkConfig)
1324
1323
  return [];
1325
1324
  const methodIds = this._sdkConfig.methods ?? [];
1326
1325
  let methods = enrichMethods(methodIds);
1327
- // Filter by identity type
1326
+ // Filter by identifier type. Passkeys are SVID-scoped and remain
1327
+ // available regardless of whether the fallback identifier is email or phone.
1328
1328
  if (this._identityType === 'phone') {
1329
- methods = methods.filter((m) => m.type === 'totp' && m.id === 'totp_sms');
1329
+ methods = methods.filter((m) => m.type === 'passkey' || m.identityType === 'phone');
1330
1330
  }
1331
1331
  else {
1332
- methods = methods.filter((m) => m.identityType === 'email');
1332
+ methods = methods.filter((m) => m.identityType === 'email' || m.identityType === undefined);
1333
1333
  }
1334
1334
  return methods;
1335
1335
  }
@@ -1359,7 +1359,9 @@ class VerificationState {
1359
1359
  this._identityType = type;
1360
1360
  }
1361
1361
  getAllowedIdentityTypes() {
1362
- const allowed = this._sdkConfig?.allowedIdentityTypes ?? ['email'];
1362
+ if (!this._sdkConfig)
1363
+ return ['email'];
1364
+ const allowed = this._sdkConfig.allowedIdentityTypes ?? ['email'];
1363
1365
  return allowed;
1364
1366
  }
1365
1367
  // --- Auth Context (OIDC/simple mode) ---
@@ -1384,11 +1386,9 @@ class VerificationState {
1384
1386
  }
1385
1387
  /**
1386
1388
  * Check if we should show passkey registration prompt
1387
- * Based on: passkey enabled, user doesn't have one, not dismissed
1389
+ * Based on: passkey enabled, the current SVID doesn't have one, not dismissed
1388
1390
  */
1389
1391
  shouldShowPasskeyPrompt() {
1390
- if (this._identityType !== 'email')
1391
- return false;
1392
1392
  if (!this.isPasskeyEnabled())
1393
1393
  return false;
1394
1394
  if (this.isPasskeyPromptDismissed())
@@ -1472,7 +1472,7 @@ class PasskeyHandler {
1472
1472
  this.accountId = config.accountId;
1473
1473
  }
1474
1474
  /**
1475
- * Check if user has registered passkeys and validate email domain
1475
+ * Check if the current identifier resolves to an SVID with registered passkeys.
1476
1476
  * @returns Check result with emailValid and hasPasskey, or null on error
1477
1477
  */
1478
1478
  async checkPasskey() {
@@ -1512,14 +1512,17 @@ class PasskeyHandler {
1512
1512
  */
1513
1513
  async openPasskeyPopup(mode, registrationToken) {
1514
1514
  return new Promise((resolve) => {
1515
- // Build popup URL. Pass identity as `email` or `phone` (mutually
1516
- // exclusive) so the popup can render and POST the correct field.
1515
+ // Registration carries the freshly verified identifier so the backend
1516
+ // can attach the credential to that SVID. Verification is discoverable:
1517
+ // the credential userHandle routes completion to the SVID.
1517
1518
  const params = new URLSearchParams({
1518
1519
  mode,
1519
1520
  origin: window.location.origin,
1520
1521
  });
1521
- const identityParam = this.state.identityType === 'phone' ? 'phone' : 'email';
1522
- params.set(identityParam, this.state.recipient);
1522
+ if (mode === 'register' && this.state.recipient) {
1523
+ const identityParam = this.state.identityType === 'phone' ? 'phone' : 'email';
1524
+ params.set(identityParam, this.state.recipient);
1525
+ }
1523
1526
  // Add auth context for OIDC/simple mode flows
1524
1527
  const authContext = this.state.authContext;
1525
1528
  if (authContext?.authRequestId) {
@@ -1576,6 +1579,9 @@ class PasskeyHandler {
1576
1579
  token: data.data.token || '',
1577
1580
  identity: data.data.identity || this.state.recipient,
1578
1581
  identityType: data.data.identity_type || 'email',
1582
+ svid: data.data.svid,
1583
+ sessionId: data.data.session_id,
1584
+ refreshToken: data.data.refresh_token,
1579
1585
  redirect: data.data.redirect,
1580
1586
  },
1581
1587
  });
@@ -1679,7 +1685,7 @@ class TotpHandler {
1679
1685
  this.state = state;
1680
1686
  }
1681
1687
  /**
1682
- * Send TOTP code via email or SMS
1688
+ * Send TOTP code via email, SMS, or voice
1683
1689
  */
1684
1690
  async send(method) {
1685
1691
  try {
@@ -1763,6 +1769,9 @@ class TotpHandler {
1763
1769
  token: response.token,
1764
1770
  identity: response.identity ?? this.state.recipient,
1765
1771
  identityType: response.identity_type ?? this.state.identityType,
1772
+ svid: response.svid,
1773
+ sessionId: response.session_id,
1774
+ refreshToken: response.refresh_token,
1766
1775
  redirect: response.redirect,
1767
1776
  },
1768
1777
  };
@@ -4103,26 +4112,33 @@ class MethodSelectView {
4103
4112
  this.methodClickHandlers = new Map();
4104
4113
  this.props = props;
4105
4114
  // Bind handlers once for proper removal
4106
- this.boundHandleBack = () => this.props.onBack();
4115
+ this.boundHandleBack = () => this.props.onBack?.();
4107
4116
  }
4108
4117
  render() {
4109
4118
  const container = div();
4110
- this.backLink = this.createBackLink();
4119
+ this.backLink = this.props.onBack ? this.createBackLink() : null;
4111
4120
  const title = document.createElement('h3');
4112
4121
  title.className = 'sv-title';
4113
4122
  title.textContent = 'Choose how to sign in';
4114
- const subtitle = document.createElement('p');
4115
- subtitle.className = 'sv-subtitle';
4116
- subtitle.textContent = escapeHtml(this.props.email);
4123
+ const email = this.props.email;
4124
+ const subtitle = email ? document.createElement('p') : null;
4125
+ if (subtitle && email) {
4126
+ subtitle.className = 'sv-subtitle';
4127
+ subtitle.textContent = escapeHtml(email);
4128
+ }
4117
4129
  const methodsContainer = div();
4118
4130
  for (const method of this.props.methods) {
4119
4131
  const methodButton = this.createMethodButton(method);
4120
4132
  this.methodButtons.push(methodButton);
4121
4133
  methodsContainer.appendChild(methodButton);
4122
4134
  }
4123
- container.appendChild(this.backLink);
4135
+ if (this.backLink) {
4136
+ container.appendChild(this.backLink);
4137
+ }
4124
4138
  container.appendChild(title);
4125
- container.appendChild(subtitle);
4139
+ if (subtitle) {
4140
+ container.appendChild(subtitle);
4141
+ }
4126
4142
  container.appendChild(methodsContainer);
4127
4143
  return container;
4128
4144
  }
@@ -4183,7 +4199,7 @@ class MethodSelectView {
4183
4199
  /**
4184
4200
  * TOTP Verification View
4185
4201
  *
4186
- * Collects and validates the 6-digit TOTP code sent via email or SMS.
4202
+ * Collects and validates the 6-digit TOTP code sent via email, SMS, or voice.
4187
4203
  */
4188
4204
  const CODE_LENGTH = 6;
4189
4205
  class TotpVerifyView {
@@ -4507,13 +4523,13 @@ class PasskeyView {
4507
4523
  this.fallbackLink = null;
4508
4524
  this.props = props;
4509
4525
  // Bind handlers once for proper removal
4510
- this.boundHandleBack = () => this.props.onBack();
4526
+ this.boundHandleBack = () => this.props.onBack?.();
4511
4527
  this.boundHandleStart = () => this.handleStart();
4512
4528
  this.boundHandleFallback = props.onFallback ? () => props.onFallback() : null;
4513
4529
  }
4514
4530
  render() {
4515
4531
  const container = div();
4516
- this.backLink = this.createBackLink();
4532
+ this.backLink = this.props.onBack ? this.createBackLink() : null;
4517
4533
  const iconContainer = div();
4518
4534
  iconContainer.appendChild(createPasskeyIcon());
4519
4535
  const title = document.createElement('h3');
@@ -4522,10 +4538,10 @@ class PasskeyView {
4522
4538
  const subtitle = document.createElement('p');
4523
4539
  subtitle.className = 'sv-subtitle';
4524
4540
  if (this.props.mode === 'register') {
4525
- subtitle.innerHTML = `Create a passkey for<br><strong>${escapeHtml(this.props.email)}</strong><br>to sign in faster next time`;
4541
+ subtitle.innerHTML = `Create a passkey for<br><strong>${escapeHtml(this.props.identityLabel)}</strong><br>to sign in faster next time`;
4526
4542
  }
4527
4543
  else {
4528
- subtitle.innerHTML = `Use your passkey to verify<br><strong>${escapeHtml(this.props.email)}</strong>`;
4544
+ subtitle.innerHTML = 'Use a passkey linked to your SparkVault Identity';
4529
4545
  }
4530
4546
  this.errorContainer = div();
4531
4547
  if (this.props.error) {
@@ -4542,7 +4558,9 @@ class PasskeyView {
4542
4558
  this.actionButton.className = 'sv-btn sv-btn-primary';
4543
4559
  this.actionButton.textContent = buttonText;
4544
4560
  this.actionButton.addEventListener('click', this.boundHandleStart);
4545
- container.appendChild(this.backLink);
4561
+ if (this.backLink) {
4562
+ container.appendChild(this.backLink);
4563
+ }
4546
4564
  container.appendChild(iconContainer);
4547
4565
  container.appendChild(title);
4548
4566
  container.appendChild(subtitle);
@@ -4558,7 +4576,7 @@ class PasskeyView {
4558
4576
  createFallbackLink() {
4559
4577
  const link = document.createElement('button');
4560
4578
  link.className = 'sv-fallback-link';
4561
- link.textContent = 'Having trouble? Use email code instead';
4579
+ link.textContent = 'Having trouble? Use a code instead';
4562
4580
  if (this.boundHandleFallback) {
4563
4581
  link.addEventListener('click', this.boundHandleFallback);
4564
4582
  }
@@ -4631,7 +4649,7 @@ class PasskeyPromptView {
4631
4649
  title.textContent = 'Add a passkey for faster sign-in?';
4632
4650
  const subtitle = document.createElement('p');
4633
4651
  subtitle.className = 'sv-subtitle';
4634
- subtitle.innerHTML = `Next time, sign in instantly as<br><strong>${escapeHtml(this.props.email)}</strong>`;
4652
+ subtitle.innerHTML = `Next time, sign in instantly as<br><strong>${escapeHtml(this.props.identityLabel)}</strong>`;
4635
4653
  // Error message if registration failed
4636
4654
  const errorContainer = div();
4637
4655
  if (this.props.error) {
@@ -5324,13 +5342,7 @@ class IdentityRenderer {
5324
5342
  ? config.branding.backdrop_blur
5325
5343
  : true;
5326
5344
  this.container.updateBackdropBlur(resolvedBackdropBlur);
5327
- // Proceed to appropriate view
5328
- if (this.recipient) {
5329
- this.showMethodSelect();
5330
- }
5331
- else {
5332
- this.showIdentityInput();
5333
- }
5345
+ await this.showInitialAuthStep();
5334
5346
  }
5335
5347
  catch (error) {
5336
5348
  this.setState(this.viewStateForConfigError(error));
@@ -5387,12 +5399,7 @@ class IdentityRenderer {
5387
5399
  ? config.branding.backdrop_blur
5388
5400
  : true;
5389
5401
  this.container.updateBackdropBlur(resolvedBackdropBlur);
5390
- if (this.recipient) {
5391
- this.showMethodSelect();
5392
- }
5393
- else {
5394
- this.showIdentityInput();
5395
- }
5402
+ await this.showInitialAuthStep();
5396
5403
  }
5397
5404
  catch (error) {
5398
5405
  this.setState(this.viewStateForConfigError(error));
@@ -5424,6 +5431,13 @@ class IdentityRenderer {
5424
5431
  this.verificationState.setViewState(state);
5425
5432
  this.render();
5426
5433
  }
5434
+ async showInitialAuthStep() {
5435
+ if (this.recipient || this.getAllowedIdentityTypes().length === 0) {
5436
+ await this.showMethodSelect();
5437
+ return;
5438
+ }
5439
+ this.showIdentityInput();
5440
+ }
5427
5441
  render() {
5428
5442
  const body = this.container.getBody();
5429
5443
  if (!body)
@@ -5472,7 +5486,7 @@ class IdentityRenderer {
5472
5486
  email: state.email,
5473
5487
  methods: state.methods,
5474
5488
  onSelectMethod: (method) => this.handleMethodSelect(method),
5475
- onBack: () => this.showIdentityInput(),
5489
+ onBack: state.email ? () => this.showIdentityInput() : undefined,
5476
5490
  });
5477
5491
  case 'totp-verify':
5478
5492
  return new TotpVerifyView({
@@ -5489,7 +5503,7 @@ class IdentityRenderer {
5489
5503
  const { passkey } = this.verificationState;
5490
5504
  const isFromPrompt = state.mode === 'register' && passkey.pendingResult !== null;
5491
5505
  return new PasskeyView({
5492
- email: state.email,
5506
+ identityLabel: state.recipient,
5493
5507
  mode: state.mode,
5494
5508
  error: state.error,
5495
5509
  onStart: () => this.handlePasskeyStart(),
@@ -5497,7 +5511,11 @@ class IdentityRenderer {
5497
5511
  ? () => this.handlePasskeyRegistrationSkip()
5498
5512
  : state.mode === 'verify'
5499
5513
  // From passkey verify, enable fallback so showMethodSelect doesn't loop back
5500
- ? () => this.handlePasskeyFallback()
5514
+ ? this.passkeyFallbackMethodsAvailable()
5515
+ ? () => this.handlePasskeyFallback()
5516
+ : this.recipient
5517
+ ? () => this.showIdentityInput()
5518
+ : undefined
5501
5519
  : () => this.showMethodSelect(),
5502
5520
  onFallback: passkey.hasPasskey && !passkey.isFallbackMode
5503
5521
  ? () => this.handlePasskeyFallback()
@@ -5506,7 +5524,7 @@ class IdentityRenderer {
5506
5524
  }
5507
5525
  case 'passkey-prompt':
5508
5526
  return new PasskeyPromptView({
5509
- email: state.email,
5527
+ identityLabel: state.recipient,
5510
5528
  onAddPasskey: () => this.handlePasskeyPromptAdd(state.pendingResult),
5511
5529
  onSkip: () => this.handlePasskeyPromptSkip(state.pendingResult),
5512
5530
  error: state.error,
@@ -5558,45 +5576,22 @@ class IdentityRenderer {
5558
5576
  }
5559
5577
  // Enrich method IDs with metadata from static registry
5560
5578
  let methods = enrichMethods(methodIds);
5561
- // Filter by identity type (phone users can only use SMS TOTP)
5562
- methods = methods.filter((m) => {
5563
- if (this.identityType === 'phone') {
5564
- // Phone users can only use SMS TOTP
5565
- return m.type === 'totp' && m.id === 'totp_sms';
5566
- }
5567
- // Email users can use email-based methods
5568
- return m.identityType === 'email' || m.identityType === undefined;
5569
- });
5570
- if (methods.length === 0) {
5571
- this.setState({
5572
- view: 'error',
5573
- message: 'No authentication methods available',
5574
- code: 'no_methods',
5579
+ if (this.recipient) {
5580
+ // Filter by identifier type. Passkeys are SVID-scoped, so they remain
5581
+ // available regardless of whether the fallback identifier is email or phone.
5582
+ methods = methods.filter((m) => {
5583
+ if (this.identityType === 'phone') {
5584
+ return m.type === 'passkey' || m.identityType === 'phone';
5585
+ }
5586
+ // Email users can use email-based methods
5587
+ return m.identityType === 'email' || m.identityType === undefined;
5575
5588
  });
5576
- return;
5577
5589
  }
5578
- // Check if passkeys are enabled and user is email-based
5579
- const hasPasskeyMethod = methods.some((m) => m.type === 'passkey');
5580
- const { passkey } = this.verificationState;
5581
- if (hasPasskeyMethod && this.identityType === 'email' && !passkey.isFallbackMode) {
5582
- this.setState({ view: 'loading' });
5583
- // Use passkey handler for the check (also validates email domain)
5584
- const checkResult = await this.passkeyHandler.checkPasskey();
5585
- // Handle invalid email domain
5586
- if (checkResult !== null && !checkResult.emailValid) {
5587
- this.showIdentityInput('This email domain cannot receive messages. Please check your email address.');
5588
- return;
5589
- }
5590
- if (checkResult?.hasPasskey === true) {
5591
- // User has passkey - go straight to passkey verification
5592
- this.setState({
5593
- view: 'passkey',
5594
- email: this.recipient,
5595
- mode: 'verify',
5596
- });
5597
- return;
5598
- }
5599
- // User doesn't have passkey - filter out passkey option
5590
+ else {
5591
+ // No PII prompt is needed when only SVID-routed methods are enabled.
5592
+ methods = methods.filter((m) => m.type === 'passkey' || m.type === 'social');
5593
+ }
5594
+ if (this.verificationState.passkey.isFallbackMode) {
5600
5595
  methods = methods.filter((m) => m.type !== 'passkey');
5601
5596
  }
5602
5597
  if (methods.length === 0) {
@@ -5628,7 +5623,11 @@ class IdentityRenderer {
5628
5623
  try {
5629
5624
  switch (method.type) {
5630
5625
  case 'totp': {
5631
- const totpMethod = method.id === 'totp_sms' ? 'sms' : 'email';
5626
+ const totpMethod = method.id === 'totp_sms'
5627
+ ? 'sms'
5628
+ : method.id === 'totp_voice'
5629
+ ? 'voice'
5630
+ : 'email';
5632
5631
  this.setState({ view: 'loading' });
5633
5632
  const result = await this.totpHandler.send(totpMethod);
5634
5633
  if (!result.success) {
@@ -5650,7 +5649,7 @@ class IdentityRenderer {
5650
5649
  case 'passkey': {
5651
5650
  this.setState({
5652
5651
  view: 'passkey',
5653
- email: this.recipient,
5652
+ recipient: this.recipient,
5654
5653
  mode: 'verify',
5655
5654
  });
5656
5655
  break;
@@ -5723,7 +5722,7 @@ class IdentityRenderer {
5723
5722
  if (!result.result.redirect && await this.shouldShowPasskeyPrompt()) {
5724
5723
  this.setState({
5725
5724
  view: 'passkey-prompt',
5726
- email: this.recipient,
5725
+ recipient: this.recipient,
5727
5726
  pendingResult: result.result,
5728
5727
  });
5729
5728
  return;
@@ -5825,7 +5824,7 @@ class IdentityRenderer {
5825
5824
  if (result.errorType === 'not_found') {
5826
5825
  this.setState({
5827
5826
  view: 'passkey',
5828
- email: this.recipient,
5827
+ recipient: this.recipient,
5829
5828
  mode: 'register',
5830
5829
  error: result.error,
5831
5830
  });
@@ -5833,7 +5832,7 @@ class IdentityRenderer {
5833
5832
  else {
5834
5833
  this.setState({
5835
5834
  view: 'passkey',
5836
- email: this.recipient,
5835
+ recipient: this.recipient,
5837
5836
  mode: currentMode,
5838
5837
  error: result.error,
5839
5838
  });
@@ -5841,13 +5840,28 @@ class IdentityRenderer {
5841
5840
  }
5842
5841
  }
5843
5842
  /**
5844
- * Handle fallback from passkey to email/SMS code.
5845
- * User clicked "Having trouble? Use email code instead".
5843
+ * Handle fallback from passkey to an identifier-based code.
5844
+ * User clicked "Having trouble? Use a code instead".
5846
5845
  */
5847
5846
  async handlePasskeyFallback() {
5848
5847
  this.verificationState.enablePasskeyFallback();
5849
5848
  await this.showMethodSelect();
5850
5849
  }
5850
+ passkeyFallbackMethodsAvailable() {
5851
+ if (!this.sdkConfig)
5852
+ return false;
5853
+ const methods = enrichMethods(this.sdkConfig.methods ?? []);
5854
+ if (!this.recipient) {
5855
+ return methods.some((m) => m.type === 'social');
5856
+ }
5857
+ return methods.some((m) => {
5858
+ if (m.type === 'passkey')
5859
+ return false;
5860
+ if (this.identityType === 'phone')
5861
+ return m.identityType === 'phone';
5862
+ return m.identityType === 'email';
5863
+ });
5864
+ }
5851
5865
  /**
5852
5866
  * Handle skipping passkey registration when coming from passkey prompt.
5853
5867
  * User clicked "Back" or cancelled registration after being prompted.
@@ -5925,7 +5939,7 @@ class IdentityRenderer {
5925
5939
  const { passkey } = this.verificationState;
5926
5940
  if (passkey.hasPasskey === null) {
5927
5941
  const checkResult = await this.passkeyHandler.checkPasskey();
5928
- // Only prompt if email is valid and user doesn't have a passkey
5942
+ // Only prompt if the verified identifier resolves to an SVID without a passkey.
5929
5943
  return checkResult !== null && checkResult.emailValid && !checkResult.hasPasskey;
5930
5944
  }
5931
5945
  return !passkey.hasPasskey;
@@ -5953,7 +5967,7 @@ class IdentityRenderer {
5953
5967
  // User cancelled browser dialog - go back to prompt so they can skip or try again
5954
5968
  this.setState({
5955
5969
  view: 'passkey-prompt',
5956
- email: this.recipient,
5970
+ recipient: this.recipient,
5957
5971
  pendingResult,
5958
5972
  });
5959
5973
  }
@@ -5962,7 +5976,7 @@ class IdentityRenderer {
5962
5976
  const errorMessage = result.error || 'Failed to create passkey. Please try again.';
5963
5977
  this.setState({
5964
5978
  view: 'passkey-prompt',
5965
- email: this.recipient,
5979
+ recipient: this.recipient,
5966
5980
  pendingResult,
5967
5981
  error: errorMessage,
5968
5982
  });
@@ -6087,6 +6101,9 @@ class IdentityRenderer {
6087
6101
  token: data.token,
6088
6102
  identity: data.identity,
6089
6103
  identityType: data.identityType || 'email',
6104
+ svid: typeof data.svid === 'string' ? data.svid : undefined,
6105
+ sessionId: typeof data.session_id === 'string' ? data.session_id : undefined,
6106
+ refreshToken: typeof data.refresh_token === 'string' ? data.refresh_token : undefined,
6090
6107
  // For simple-mode flows the server also emits a signed
6091
6108
  // success-callback URL; without it the SDK has nowhere to send
6092
6109
  // the user after WebSocket success.
@@ -6133,7 +6150,7 @@ class IdentityRenderer {
6133
6150
  if (!result.redirect && await this.shouldShowPasskeyPrompt()) {
6134
6151
  this.setState({
6135
6152
  view: 'passkey-prompt',
6136
- email: this.recipient,
6153
+ recipient: this.recipient,
6137
6154
  pendingResult: result,
6138
6155
  });
6139
6156
  return;
@@ -6525,6 +6542,11 @@ class IdentityModule {
6525
6542
  * });
6526
6543
  */
6527
6544
  async verify(options = {}) {
6545
+ const redirectResult = await this.consumeRedirectResult();
6546
+ if (redirectResult) {
6547
+ options.onSuccess?.(redirectResult);
6548
+ return redirectResult;
6549
+ }
6528
6550
  if (this.renderer) {
6529
6551
  this.renderer.close();
6530
6552
  }
@@ -6636,8 +6658,19 @@ class IdentityModule {
6636
6658
  observer?.observe(document.body, { childList: true, subtree: true });
6637
6659
  });
6638
6660
  };
6639
- // Defer attachment until DOM is ready
6640
- onDomReady(attachToElements);
6661
+ // Defer attachment until DOM is ready, then complete any full-page
6662
+ // social-login redirect result before the user has to click again.
6663
+ onDomReady(() => {
6664
+ attachToElements();
6665
+ this.consumeRedirectResult()
6666
+ .then((result) => {
6667
+ if (result)
6668
+ options.onSuccess?.(result);
6669
+ })
6670
+ .catch((error) => {
6671
+ options.onError?.(error instanceof Error ? error : new Error(String(error)));
6672
+ });
6673
+ });
6641
6674
  // Return cleanup function
6642
6675
  return () => {
6643
6676
  observer?.disconnect();
@@ -6675,6 +6708,34 @@ class IdentityModule {
6675
6708
  }
6676
6709
  return payload;
6677
6710
  }
6711
+ /**
6712
+ * Complete full-page redirect results produced by social-login flows.
6713
+ * The Identity Product redirects back with `#token=...` so the token does
6714
+ * not hit server logs. Consume it once, validate the issuer/expiry shape,
6715
+ * then remove it from the URL bar.
6716
+ */
6717
+ async consumeRedirectResult() {
6718
+ if (typeof window === 'undefined' || !window.location.hash) {
6719
+ return null;
6720
+ }
6721
+ const params = new URLSearchParams(window.location.hash.slice(1));
6722
+ const token = params.get('token');
6723
+ if (!token) {
6724
+ return null;
6725
+ }
6726
+ const claims = await this.verifyToken(token);
6727
+ const result = {
6728
+ token,
6729
+ identity: claims.identity,
6730
+ identityType: claims.identity_type,
6731
+ svid: claims.svid,
6732
+ sessionId: claims.session_id,
6733
+ };
6734
+ if (typeof window.history?.replaceState === 'function') {
6735
+ window.history.replaceState(window.history.state, document.title, `${window.location.pathname}${window.location.search}`);
6736
+ }
6737
+ return result;
6738
+ }
6678
6739
  /**
6679
6740
  * Close the identity dialog/inline UI if open.
6680
6741
  */