@proveanything/smartlinks-auth-ui 0.4.3 → 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.
- package/dist/components/SmartlinksAuthUI.d.ts.map +1 -1
- package/dist/components/SmartlinksFrame/useIframeMessages.d.ts.map +1 -1
- package/dist/index.esm.js +84 -10
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +84 -10
- package/dist/index.js.map +1 -1
- package/dist/types/iframeMessages.d.ts +2 -0
- package/dist/types/iframeMessages.d.ts.map +1 -1
- package/dist/utils/errorHandling.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -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,
|
|
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,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,UAAU,CAAC;IAEvB,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,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,
|
|
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,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,UAAU,CAAC;IAEvB,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,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
|
@@ -12401,8 +12401,32 @@ function getFriendlyErrorMessage(error) {
|
|
|
12401
12401
|
// Fall back to the server's message (already human-readable from backend)
|
|
12402
12402
|
return error.message;
|
|
12403
12403
|
}
|
|
12404
|
-
// Handle standard Error objects
|
|
12404
|
+
// Handle standard Error objects
|
|
12405
12405
|
if (error instanceof Error) {
|
|
12406
|
+
// SDK bug workaround: SDK may do `throw new Error(responseBodyObject)` which produces
|
|
12407
|
+
// message "[object Object]". Check for API error properties attached to the Error instance.
|
|
12408
|
+
const errAny = error;
|
|
12409
|
+
// Check if the Error has API error properties directly attached (e.g., error.statusCode, error.errorCode)
|
|
12410
|
+
if (typeof errAny.statusCode === 'number' || errAny.errorCode || errAny.response) {
|
|
12411
|
+
// Try to extract from attached properties
|
|
12412
|
+
const apiLike = errAny.response || errAny;
|
|
12413
|
+
if (isApiErrorLike(apiLike)) {
|
|
12414
|
+
return getFriendlyErrorMessage(apiLike);
|
|
12415
|
+
}
|
|
12416
|
+
}
|
|
12417
|
+
// Check if the Error has a `cause` with API error details (modern Error cause pattern)
|
|
12418
|
+
if (errAny.cause && typeof errAny.cause === 'object') {
|
|
12419
|
+
if (isApiErrorLike(errAny.cause)) {
|
|
12420
|
+
return getFriendlyErrorMessage(errAny.cause);
|
|
12421
|
+
}
|
|
12422
|
+
}
|
|
12423
|
+
// If the message is "[object Object]", the error was constructed from a plain object
|
|
12424
|
+
// This is useless - return a generic message instead
|
|
12425
|
+
if (error.message === '[object Object]') {
|
|
12426
|
+
// Log the actual error for debugging
|
|
12427
|
+
console.warn('[AuthKit] Error with [object Object] message. Raw error:', JSON.stringify(errAny, Object.getOwnPropertyNames(errAny)));
|
|
12428
|
+
return 'An unexpected error occurred. Please try again.';
|
|
12429
|
+
}
|
|
12406
12430
|
// Check if the message itself contains a known API error pattern
|
|
12407
12431
|
if (/already (registered|exists)/i.test(error.message)) {
|
|
12408
12432
|
return 'This email is already registered.';
|
|
@@ -12474,6 +12498,27 @@ function getErrorCode(error) {
|
|
|
12474
12498
|
}
|
|
12475
12499
|
return undefined;
|
|
12476
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
|
+
}
|
|
12477
12522
|
|
|
12478
12523
|
// VERSION: Update this when making changes to help identify which version is running
|
|
12479
12524
|
const AUTH_UI_VERSION = '44';
|
|
@@ -13216,10 +13261,18 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
13216
13261
|
if (response.token) {
|
|
13217
13262
|
// Check for account lock or verification requirements
|
|
13218
13263
|
if (response.accountLocked) {
|
|
13219
|
-
|
|
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;
|
|
13220
13269
|
}
|
|
13221
13270
|
if (response.requiresEmailVerification) {
|
|
13222
|
-
|
|
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;
|
|
13223
13276
|
}
|
|
13224
13277
|
await auth.login(response.token, response.user, response.accountData, false, getExpirationFromResponse(response));
|
|
13225
13278
|
setAuthSuccess(true);
|
|
@@ -13228,14 +13281,26 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
13228
13281
|
// Note: No automatic redirect - app controls navigation via onAuthSuccess callback
|
|
13229
13282
|
}
|
|
13230
13283
|
else {
|
|
13231
|
-
|
|
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;
|
|
13232
13290
|
}
|
|
13233
13291
|
}
|
|
13234
13292
|
}
|
|
13235
13293
|
catch (err) {
|
|
13294
|
+
// Debug: log the raw error shape to help diagnose SDK error wrapping issues
|
|
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
|
+
}
|
|
13236
13302
|
// Check if error is about email already registered (409 conflict)
|
|
13237
|
-
|
|
13238
|
-
if (mode === 'register' && (isConflictError(err) ||
|
|
13303
|
+
else if (mode === 'register' && (isConflictError(err) ||
|
|
13239
13304
|
(err instanceof Error && /already (registered|exists)/i.test(err.message)))) {
|
|
13240
13305
|
setShowResendVerification(true);
|
|
13241
13306
|
setResendEmail(data.email);
|
|
@@ -13244,7 +13309,8 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
13244
13309
|
else {
|
|
13245
13310
|
setError(getFriendlyErrorMessage(err));
|
|
13246
13311
|
}
|
|
13247
|
-
|
|
13312
|
+
const friendlyMsg = getFriendlyErrorMessage(err);
|
|
13313
|
+
onAuthError?.(err instanceof Error ? new Error(friendlyMsg) : new Error(friendlyMsg));
|
|
13248
13314
|
}
|
|
13249
13315
|
finally {
|
|
13250
13316
|
setLoading(false);
|
|
@@ -13832,14 +13898,14 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
13832
13898
|
color: config?.branding?.inheritHostStyles
|
|
13833
13899
|
? 'hsl(var(--foreground, 215 25% 15%))'
|
|
13834
13900
|
: (resolvedTheme === 'dark' ? '#f1f5f9' : '#374151')
|
|
13835
|
-
}, children: "Verification
|
|
13901
|
+
}, children: "Email Verification Required" }), jsx("p", { style: {
|
|
13836
13902
|
marginBottom: '1rem',
|
|
13837
13903
|
fontSize: '0.875rem',
|
|
13838
13904
|
color: config?.branding?.inheritHostStyles
|
|
13839
13905
|
? 'hsl(var(--muted-foreground, 215 15% 45%))'
|
|
13840
13906
|
: (resolvedTheme === 'dark' ? '#94a3b8' : '#6B7280'),
|
|
13841
13907
|
lineHeight: '1.5'
|
|
13842
|
-
}, children: "Your
|
|
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 ? {
|
|
13843
13909
|
width: '100%',
|
|
13844
13910
|
padding: '0.625rem',
|
|
13845
13911
|
marginBottom: '1rem',
|
|
@@ -14832,7 +14898,15 @@ function useIframeMessages(iframeRef, options) {
|
|
|
14832
14898
|
}
|
|
14833
14899
|
catch (err) {
|
|
14834
14900
|
console.error('[SmartlinksFrame] Proxy error:', err);
|
|
14835
|
-
|
|
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
|
+
}
|
|
14836
14910
|
onErrorRef.current?.(err);
|
|
14837
14911
|
}
|
|
14838
14912
|
sendResponse(event.source, event.origin, response);
|