@proveanything/smartlinks-auth-ui 0.4.4 → 0.4.5

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.
@@ -1 +1 @@
1
- {"version":3,"file":"SmartlinksAuthUI.d.ts","sourceRoot":"","sources":["../../src/components/SmartlinksAuthUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAY5D,OAAO,KAAK,EAAE,qBAAqB,EAAyF,MAAM,UAAU,CAAC;AA8I7I,QAAA,MAAM,mBAAmB,QAAa,OAAO,CAAC,IAAI,CAmCjD,CAAC;AAwEF,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAK/B,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CA8sD5D,CAAC"}
1
+ {"version":3,"file":"SmartlinksAuthUI.d.ts","sourceRoot":"","sources":["../../src/components/SmartlinksAuthUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAY5D,OAAO,KAAK,EAAE,qBAAqB,EAAyF,MAAM,UAAU,CAAC;AA8I7I,QAAA,MAAM,mBAAmB,QAAa,OAAO,CAAC,IAAI,CAmCjD,CAAC;AAwEF,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAK/B,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAguD5D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useIframeMessages.d.ts","sourceRoot":"","sources":["../../../src/components/SmartlinksFrame/useIframeMessages.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAQV,UAAU,EACX,MAAM,4BAA4B,CAAC;AAepC,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAA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,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrI,MAAM,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;IACtE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AASD;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,iBAAiB,CAAC,EAC7C,OAAO,EAAE,oBAAoB,GAC5B,IAAI,CAsbN"}
package/dist/index.esm.js CHANGED
@@ -12498,6 +12498,27 @@ function getErrorCode(error) {
12498
12498
  }
12499
12499
  return undefined;
12500
12500
  }
12501
+ /**
12502
+ * Error codes that indicate the user needs to verify their email.
12503
+ */
12504
+ const EMAIL_VERIFICATION_ERROR_CODES = new Set([
12505
+ 'EMAIL_NOT_VERIFIED',
12506
+ 'ACCOUNT_LOCKED',
12507
+ 'EMAIL_VERIFICATION_EXPIRED',
12508
+ ]);
12509
+ /**
12510
+ * Checks if an error requires email verification action from the user.
12511
+ */
12512
+ function requiresEmailVerification(error) {
12513
+ const code = getErrorCode(error);
12514
+ if (code && EMAIL_VERIFICATION_ERROR_CODES.has(code))
12515
+ return true;
12516
+ // Also check the flag from the response body
12517
+ if (error && typeof error === 'object' && 'requiresEmailVerification' in error) {
12518
+ return error.requiresEmailVerification === true;
12519
+ }
12520
+ return false;
12521
+ }
12501
12522
 
12502
12523
  // VERSION: Update this when making changes to help identify which version is running
12503
12524
  const AUTH_UI_VERSION = '44';
@@ -13240,10 +13261,18 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
13240
13261
  if (response.token) {
13241
13262
  // Check for account lock or verification requirements
13242
13263
  if (response.accountLocked) {
13243
- throw new Error('Your account has been locked due to unverified email. Please check your email or request a new verification link.');
13264
+ setShowResendVerification(true);
13265
+ setResendEmail(data.email);
13266
+ setError('Your account has been locked due to unverified email. Click below to resend the verification link.');
13267
+ setLoading(false);
13268
+ return;
13244
13269
  }
13245
13270
  if (response.requiresEmailVerification) {
13246
- throw new Error('Please verify your email before logging in. Check your inbox for the verification link.');
13271
+ setShowResendVerification(true);
13272
+ setResendEmail(data.email);
13273
+ setError('Please verify your email before signing in. Click below to resend the verification link.');
13274
+ setLoading(false);
13275
+ return;
13247
13276
  }
13248
13277
  await auth.login(response.token, response.user, response.accountData, false, getExpirationFromResponse(response));
13249
13278
  setAuthSuccess(true);
@@ -13252,16 +13281,26 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
13252
13281
  // Note: No automatic redirect - app controls navigation via onAuthSuccess callback
13253
13282
  }
13254
13283
  else {
13255
- throw new Error('Authentication failed - please verify your email before logging in.');
13284
+ // No token returned - likely requires email verification
13285
+ setShowResendVerification(true);
13286
+ setResendEmail(data.email);
13287
+ setError('Please verify your email before signing in. Click below to resend the verification link.');
13288
+ setLoading(false);
13289
+ return;
13256
13290
  }
13257
13291
  }
13258
13292
  }
13259
13293
  catch (err) {
13260
13294
  // Debug: log the raw error shape to help diagnose SDK error wrapping issues
13261
13295
  log.error('handleEmailAuth error:', typeof err, err instanceof Error ? `Error.message=${err.message}` : '', JSON.stringify(err, Object.getOwnPropertyNames(err || {})));
13296
+ // Check if error requires email verification (403 EMAIL_NOT_VERIFIED, ACCOUNT_LOCKED, etc.)
13297
+ if (requiresEmailVerification(err)) {
13298
+ setShowResendVerification(true);
13299
+ setResendEmail(data.email);
13300
+ setError(getFriendlyErrorMessage(err) + ' Click below to resend the verification link.');
13301
+ }
13262
13302
  // Check if error is about email already registered (409 conflict)
13263
- // Handle both SmartlinksApiError (statusCode 409) and plain Error with keyword matching
13264
- if (mode === 'register' && (isConflictError(err) ||
13303
+ else if (mode === 'register' && (isConflictError(err) ||
13265
13304
  (err instanceof Error && /already (registered|exists)/i.test(err.message)))) {
13266
13305
  setShowResendVerification(true);
13267
13306
  setResendEmail(data.email);
@@ -13859,14 +13898,14 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
13859
13898
  color: config?.branding?.inheritHostStyles
13860
13899
  ? 'hsl(var(--foreground, 215 25% 15%))'
13861
13900
  : (resolvedTheme === 'dark' ? '#f1f5f9' : '#374151')
13862
- }, children: "Verification Link Expired" }), jsx("p", { style: {
13901
+ }, children: "Email Verification Required" }), jsx("p", { style: {
13863
13902
  marginBottom: '1rem',
13864
13903
  fontSize: '0.875rem',
13865
13904
  color: config?.branding?.inheritHostStyles
13866
13905
  ? 'hsl(var(--muted-foreground, 215 15% 45%))'
13867
13906
  : (resolvedTheme === 'dark' ? '#94a3b8' : '#6B7280'),
13868
13907
  lineHeight: '1.5'
13869
- }, children: "Your verification link has expired or is no longer valid. Please enter your email address below and we'll send you a new verification link." }), jsx("input", { type: "email", value: resendEmail || '', onChange: (e) => setResendEmail(e.target.value), placeholder: "your@email.com", className: config?.branding?.inheritHostStyles ? 'auth-input' : undefined, style: config?.branding?.inheritHostStyles ? {
13908
+ }, children: "Your email address needs to be verified before you can sign in. Enter your email below and we'll send you a verification link." }), jsx("input", { type: "email", value: resendEmail || '', onChange: (e) => setResendEmail(e.target.value), placeholder: "your@email.com", className: config?.branding?.inheritHostStyles ? 'auth-input' : undefined, style: config?.branding?.inheritHostStyles ? {
13870
13909
  width: '100%',
13871
13910
  padding: '0.625rem',
13872
13911
  marginBottom: '1rem',
@@ -14859,7 +14898,15 @@ function useIframeMessages(iframeRef, options) {
14859
14898
  }
14860
14899
  catch (err) {
14861
14900
  console.error('[SmartlinksFrame] Proxy error:', err);
14862
- response.error = err?.message || 'Unknown error';
14901
+ const statusCode = err?.statusCode ?? err?.response?.status ?? err?.response?.statusCode;
14902
+ const errorBody = err?.details ?? err?.response?.data ?? err?.response ?? err?.cause;
14903
+ response.error = typeof err?.message === 'string' ? err.message : 'Unknown error';
14904
+ if (typeof statusCode === 'number') {
14905
+ response.statusCode = statusCode;
14906
+ }
14907
+ if (errorBody && typeof errorBody === 'object') {
14908
+ response.errorBody = JSON.parse(JSON.stringify(errorBody));
14909
+ }
14863
14910
  onErrorRef.current?.(err);
14864
14911
  }
14865
14912
  sendResponse(event.source, event.origin, response);