@proveanything/smartlinks-auth-ui 0.1.38 → 0.1.40

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.
@@ -6,6 +6,7 @@ interface PasswordResetFormProps {
6
6
  loading: boolean;
7
7
  error?: string;
8
8
  success?: boolean;
9
+ successMessage?: string;
9
10
  token?: string;
10
11
  }
11
12
  export declare const PasswordResetForm: React.FC<PasswordResetFormProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"PasswordResetForm.d.ts","sourceRoot":"","sources":["../../src/components/PasswordResetForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,gBAAgB,CAAC;AAExB,UAAU,sBAAsB;IAC9B,QAAQ,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/E,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAwL9D,CAAC"}
1
+ {"version":3,"file":"PasswordResetForm.d.ts","sourceRoot":"","sources":["../../src/components/PasswordResetForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,gBAAgB,CAAC;AAExB,UAAU,sBAAsB;IAC9B,QAAQ,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/E,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAyL9D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"SmartlinksAuthUI.d.ts","sourceRoot":"","sources":["../../src/components/SmartlinksAuthUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAW5D,OAAO,KAAK,EAAE,qBAAqB,EAAuD,MAAM,UAAU,CAAC;AAgI3G,QAAA,MAAM,mBAAmB,QAAa,OAAO,CAAC,IAAI,CA+CjD,CAAC;AAyFF,OAAO,EAAE,mBAAmB,EAAE,CAAC;AA8B/B,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAk6C5D,CAAC"}
1
+ {"version":3,"file":"SmartlinksAuthUI.d.ts","sourceRoot":"","sources":["../../src/components/SmartlinksAuthUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAW5D,OAAO,KAAK,EAAE,qBAAqB,EAAuD,MAAM,UAAU,CAAC;AAgI3G,QAAA,MAAM,mBAAmB,QAAa,OAAO,CAAC,IAAI,CA+CjD,CAAC;AAyFF,OAAO,EAAE,mBAAmB,EAAE,CAAC;AA8B/B,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CA48C5D,CAAC"}
package/dist/index.esm.js CHANGED
@@ -10671,7 +10671,7 @@ const PhoneAuthForm = ({ onSubmit, onBack, loading, error, }) => {
10671
10671
  : 'Resend code' }) })] })), jsx("button", { type: "submit", className: "auth-button auth-button-primary", disabled: loading, children: loading ? (jsx("span", { className: "auth-spinner" })) : codeSent ? ('Verify Code') : ('Send Code') }), jsx("div", { className: "auth-divider", children: jsx("button", { type: "button", className: "auth-link auth-link-bold", onClick: onBack, disabled: loading, children: "\u2190 Back to login" }) })] }));
10672
10672
  };
10673
10673
 
10674
- const PasswordResetForm = ({ onSubmit, onBack, loading, error, success, token, }) => {
10674
+ const PasswordResetForm = ({ onSubmit, onBack, loading, error, success, successMessage, token, }) => {
10675
10675
  const [email, setEmail] = useState('');
10676
10676
  const [password, setPassword] = useState('');
10677
10677
  const [confirmPassword, setConfirmPassword] = useState('');
@@ -10698,8 +10698,8 @@ const PasswordResetForm = ({ onSubmit, onBack, loading, error, success, token, }
10698
10698
  };
10699
10699
  if (success) {
10700
10700
  return (jsxs("div", { className: "auth-form", children: [jsxs("div", { className: "auth-form-header", children: [jsx("div", { style: { textAlign: 'center', marginBottom: '1rem' }, children: jsxs("svg", { width: "64", height: "64", viewBox: "0 0 64 64", fill: "none", style: { margin: '0 auto' }, children: [jsx("circle", { cx: "32", cy: "32", r: "32", fill: "#10b981", fillOpacity: "0.1" }), jsx("path", { d: "M20 32l8 8 16-16", stroke: "#10b981", strokeWidth: "4", strokeLinecap: "round", strokeLinejoin: "round" })] }) }), jsx("h2", { className: "auth-form-title", children: token ? 'Password reset!' : 'Check your email' }), jsx("p", { className: "auth-form-subtitle", children: token
10701
- ? 'Your password has been successfully reset. You can now sign in with your new password.'
10702
- : `We've sent password reset instructions to ${email}` })] }), jsx("button", { type: "button", className: "auth-button auth-button-primary", onClick: onBack, children: "Back to Sign in" })] }));
10701
+ ? (successMessage || 'Your password has been successfully reset. You can now sign in with your new password.')
10702
+ : (successMessage || `We've sent password reset instructions to ${email}`) })] }), jsx("button", { type: "button", className: "auth-button auth-button-primary", onClick: onBack, children: "Back to Sign in" })] }));
10703
10703
  }
10704
10704
  return (jsxs("form", { className: "auth-form", onSubmit: handleSubmit, children: [jsxs("div", { className: "auth-form-header", children: [jsx("h2", { className: "auth-form-title", children: token ? 'Set new password' : 'Reset your password' }), jsx("p", { className: "auth-form-subtitle", children: token
10705
10705
  ? 'Enter your new password below.'
@@ -12404,6 +12404,7 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
12404
12404
  const [showRequestNewReset, setShowRequestNewReset] = useState(false);
12405
12405
  const [resetRequestEmail, setResetRequestEmail] = useState();
12406
12406
  const [resetToken, setResetToken] = useState(); // Store the reset token from URL
12407
+ const [resetEmail, setResetEmail] = useState(); // Store email from token verification for auto-login
12407
12408
  const [config, setConfig] = useState(null);
12408
12409
  const [configLoading, setConfigLoading] = useState(!skipConfigFetch);
12409
12410
  const [showEmailForm, setShowEmailForm] = useState(false); // Track if email form should be shown when emailDisplayMode is 'button'
@@ -12760,8 +12761,15 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
12760
12761
  else if (urlMode === 'resetPassword') {
12761
12762
  log.log('Verifying reset token:', token);
12762
12763
  // Verify token is valid, then show password reset form
12763
- await api.verifyResetToken(token);
12764
+ const verifyResult = await api.verifyResetToken(token);
12765
+ // Check if token is valid before proceeding
12766
+ if (!verifyResult.valid) {
12767
+ throw new Error(verifyResult.message || 'Invalid or expired token');
12768
+ }
12764
12769
  setResetToken(token); // Store token for use in password reset
12770
+ if (verifyResult.email) {
12771
+ setResetEmail(verifyResult.email); // Store email for auto-login after reset
12772
+ }
12765
12773
  setMode('reset-password');
12766
12774
  // Clear the URL parameters
12767
12775
  const cleanUrl = window.location.href.split('?')[0];
@@ -13394,14 +13402,42 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
13394
13402
  // Complete password reset with token
13395
13403
  console.log(`${LOG_PREFIX} 🔑 Completing password reset with token`);
13396
13404
  await api.completePasswordReset(resetToken, emailOrPassword);
13405
+ // Auto-login with the new password if we have the email
13406
+ if (resetEmail) {
13407
+ console.log(`${LOG_PREFIX} 🔑 Auto-signing in after password reset`);
13408
+ try {
13409
+ const loginResponse = await api.login(resetEmail, emailOrPassword);
13410
+ if (loginResponse.token) {
13411
+ auth.login(loginResponse.token, loginResponse.user, loginResponse.accountData, false);
13412
+ setAuthSuccess(true);
13413
+ setSuccessMessage('Password reset successful! You are now signed in.');
13414
+ onAuthSuccess(loginResponse.token, loginResponse.user, loginResponse.accountData);
13415
+ // Clear reset state
13416
+ setResetToken(undefined);
13417
+ setResetEmail(undefined);
13418
+ return; // Exit early - we've handled everything
13419
+ }
13420
+ }
13421
+ catch (loginErr) {
13422
+ // Auto-login failed, fall back to showing success message
13423
+ console.log(`${LOG_PREFIX} ⚠️ Auto-login after reset failed, showing manual login prompt`, loginErr);
13424
+ }
13425
+ }
13426
+ // Fallback: show success but require manual login
13397
13427
  setResetSuccess(true);
13398
- setResetToken(undefined); // Clear token after successful reset
13428
+ setSuccessMessage('Password reset successful! Please sign in with your new password.');
13429
+ setResetToken(undefined);
13430
+ setResetEmail(undefined);
13399
13431
  }
13400
13432
  else {
13401
13433
  // Request password reset email
13402
13434
  console.log(`${LOG_PREFIX} 🔑 Requesting password reset email with redirectUrl:`, effectiveRedirectUrl);
13403
- await api.requestPasswordReset(emailOrPassword, effectiveRedirectUrl);
13435
+ const result = await api.requestPasswordReset(emailOrPassword, effectiveRedirectUrl);
13404
13436
  setResetSuccess(true);
13437
+ // Use backend message if available
13438
+ if (result?.message) {
13439
+ setSuccessMessage(result.message);
13440
+ }
13405
13441
  }
13406
13442
  }
13407
13443
  catch (err) {
@@ -13450,7 +13486,9 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
13450
13486
  setMode('login');
13451
13487
  setResetSuccess(false);
13452
13488
  setResetToken(undefined); // Clear token when going back
13453
- }, loading: loading, error: error, success: resetSuccess, token: resetToken })) : (mode === 'login' || mode === 'register') ? (jsx(Fragment, { children: showResendVerification ? (jsxs("div", { style: { marginTop: '1rem', padding: '1.5rem', backgroundColor: 'rgba(79, 70, 229, 0.05)', borderRadius: '0.5rem' }, children: [jsx("h3", { style: { marginBottom: '0.75rem', fontSize: '1rem', fontWeight: 600, color: 'var(--auth-text-color, #374151)' }, children: "Verification Link Expired" }), jsx("p", { style: { marginBottom: '1rem', fontSize: '0.875rem', color: 'var(--auth-text-color, #6B7280)', lineHeight: '1.5' }, 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", style: {
13489
+ setResetEmail(undefined); // Clear email when going back
13490
+ setSuccessMessage(undefined); // Clear success message
13491
+ }, loading: loading, error: error, success: resetSuccess, successMessage: successMessage, token: resetToken })) : (mode === 'login' || mode === 'register') ? (jsx(Fragment, { children: showResendVerification ? (jsxs("div", { style: { marginTop: '1rem', padding: '1.5rem', backgroundColor: 'rgba(79, 70, 229, 0.05)', borderRadius: '0.5rem' }, children: [jsx("h3", { style: { marginBottom: '0.75rem', fontSize: '1rem', fontWeight: 600, color: 'var(--auth-text-color, #374151)' }, children: "Verification Link Expired" }), jsx("p", { style: { marginBottom: '1rem', fontSize: '0.875rem', color: 'var(--auth-text-color, #6B7280)', lineHeight: '1.5' }, 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", style: {
13454
13492
  width: '100%',
13455
13493
  padding: '0.625rem',
13456
13494
  marginBottom: '1rem',