@dloizides/auth-web 1.11.0 → 1.12.1

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/index.mjs CHANGED
@@ -113,7 +113,7 @@ function AuthScreen({
113
113
  ] });
114
114
  }
115
115
 
116
- // src/components/labels.ts
116
+ // src/components/labels/loginLabels.ts
117
117
  var DEFAULT_LOGIN_LABELS = {
118
118
  title: "Sign in",
119
119
  subtitle: "Welcome back",
@@ -128,6 +128,8 @@ var DEFAULT_LOGIN_LABELS = {
128
128
  invalidCredentials: "Incorrect username or password.",
129
129
  missingFields: "Enter both your username and password."
130
130
  };
131
+
132
+ // src/components/labels/forgotPasswordLabels.ts
131
133
  var DEFAULT_FORGOT_PASSWORD_LABELS = {
132
134
  title: "Forgot password",
133
135
  description: "Enter your email and we will send you a reset link.",
@@ -144,6 +146,8 @@ var DEFAULT_FORGOT_PASSWORD_FIELDS_LABELS = {
144
146
  cancel: "Cancel",
145
147
  close: "Close"
146
148
  };
149
+
150
+ // src/components/labels/otpLabels.ts
147
151
  var DEFAULT_OTP_LABELS = {
148
152
  requestTitle: "Sign in with a code",
149
153
  requestDescription: "Enter your email and we will send you a one-time code.",
@@ -164,6 +168,8 @@ var DEFAULT_OTP_LABELS = {
164
168
  resending: "Resending...",
165
169
  changeEmail: "Use a different email"
166
170
  };
171
+
172
+ // src/components/labels/pinLabels.ts
167
173
  var DEFAULT_PIN_LABELS = {
168
174
  title: "Enter your event PIN",
169
175
  description: "Enter the PIN for this event to sign in.",
@@ -174,6 +180,8 @@ var DEFAULT_PIN_LABELS = {
174
180
  missingPin: "Enter your event PIN.",
175
181
  invalidPin: "That PIN is incorrect, has expired, or is locked out."
176
182
  };
183
+
184
+ // src/components/labels/devicePinLabels.ts
177
185
  var DEFAULT_DEVICE_PIN_UNLOCK_LABELS = {
178
186
  title: "Welcome back, {name}",
179
187
  titleNoName: "Welcome back",
@@ -231,6 +239,8 @@ var DEFAULT_DEVICE_PIN_SETTINGS_LABELS = {
231
239
  disabling: "Disabling...",
232
240
  disableFailed: "Could not disable PIN sign-in. Try again later."
233
241
  };
242
+
243
+ // src/components/labels/passkeyLabels.ts
234
244
  var DEFAULT_PASSKEY_LOGIN_LABELS = {
235
245
  signInButton: "Sign in with a passkey",
236
246
  signInHint: "Use your fingerprint, face, or security key to sign in",
@@ -246,6 +256,8 @@ var DEFAULT_PASSKEY_SETTINGS_LABELS = {
246
256
  addHint: "Start setting up a passkey for this account",
247
257
  registeredSuccess: "Your passkey was added. You can now use it to sign in."
248
258
  };
259
+
260
+ // src/components/labels/preferredMethodLabels.ts
249
261
  var DEFAULT_PREFERRED_METHOD_SETTINGS_LABELS = {
250
262
  title: "Preferred sign-in method",
251
263
  description: "Pick how you usually sign in. We will show this method first on your devices.",
@@ -261,6 +273,8 @@ var DEFAULT_PREFERRED_METHOD_HINT_LABELS = {
261
273
  pin: "You usually sign in with your quick PIN on this account.",
262
274
  passkey: "You usually sign in with a passkey."
263
275
  };
276
+
277
+ // src/components/labels/demoLabels.ts
264
278
  var DEFAULT_DEMO_CREDENTIALS_HINT_LABELS = {
265
279
  title: "Demo access",
266
280
  description: "Explore the full product with our shared demo account.",
@@ -269,6 +283,8 @@ var DEFAULT_DEMO_CREDENTIALS_HINT_LABELS = {
269
283
  useCredentials: "Use these credentials",
270
284
  useCredentialsHint: "Fill the sign-in form with the demo username and password"
271
285
  };
286
+
287
+ // src/components/labels/resetPasswordLabels.ts
272
288
  var DEFAULT_RESET_PASSWORD_LABELS = {
273
289
  title: "Reset password",
274
290
  description: "Choose a new password for your account.",
@@ -493,21 +509,64 @@ function useAuthStyles(theme) {
493
509
  });
494
510
  }, [theme]);
495
511
  }
512
+
513
+ // src/components/PrefillIntent.ts
514
+ var PrefillIntent = /* @__PURE__ */ ((PrefillIntent2) => {
515
+ PrefillIntent2["Explicit"] = "explicit";
516
+ PrefillIntent2["Opportunistic"] = "opportunistic";
517
+ return PrefillIntent2;
518
+ })(PrefillIntent || {});
519
+
520
+ // src/components/useLoginPrefill.ts
496
521
  function useLoginPrefill({
497
522
  initialUsername,
498
523
  initialPassword,
499
- prefillNonce
524
+ prefillNonce,
525
+ prefillIntent
500
526
  }) {
501
527
  const [username, setUsername] = useState(initialUsername ?? "");
502
528
  const [password, setPassword] = useState(initialPassword ?? "");
503
529
  const [appliedNonce, setAppliedNonce] = useState(prefillNonce);
504
530
  if (prefillNonce !== appliedNonce) {
505
531
  setAppliedNonce(prefillNonce);
506
- setUsername(initialUsername ?? "");
507
- setPassword(initialPassword ?? "");
532
+ const isPristine = username.length === 0 && password.length === 0;
533
+ const mayApply = prefillIntent !== "opportunistic" /* Opportunistic */ || isPristine;
534
+ if (mayApply) {
535
+ setUsername(initialUsername ?? "");
536
+ setPassword(initialPassword ?? "");
537
+ }
508
538
  }
509
539
  return { username, password, setUsername, setPassword };
510
540
  }
541
+ function useLoginSubmit({
542
+ username,
543
+ password,
544
+ login,
545
+ onSuccess,
546
+ missingFieldsLabel,
547
+ invalidCredentialsLabel
548
+ }) {
549
+ const [errorText, setErrorText] = useState(null);
550
+ const runLogin = useCallback(async () => {
551
+ setErrorText(null);
552
+ const trimmedUsername = username.trim();
553
+ const hasMissingField = trimmedUsername.length === 0 || password.length === 0;
554
+ if (hasMissingField) {
555
+ setErrorText(missingFieldsLabel);
556
+ return;
557
+ }
558
+ try {
559
+ const user = await login({ username: trimmedUsername, password });
560
+ onSuccess(user);
561
+ } catch {
562
+ setErrorText(invalidCredentialsLabel);
563
+ }
564
+ }, [username, password, login, onSuccess, missingFieldsLabel, invalidCredentialsLabel]);
565
+ const handleSubmit = useCallback(() => {
566
+ void runLogin();
567
+ }, [runLogin]);
568
+ return { errorText, handleSubmit };
569
+ }
511
570
  var BffAuthStatus = /* @__PURE__ */ ((BffAuthStatus2) => {
512
571
  BffAuthStatus2["Loading"] = "loading";
513
572
  BffAuthStatus2["Authenticated"] = "authenticated";
@@ -622,7 +681,8 @@ function LoginForm({
622
681
  chromeless = false,
623
682
  initialUsername,
624
683
  initialPassword,
625
- prefillNonce
684
+ prefillNonce,
685
+ prefillIntent
626
686
  }) {
627
687
  const theme = useAuthTheme(themeProp);
628
688
  const styles3 = useAuthStyles(theme);
@@ -634,27 +694,17 @@ function LoginForm({
634
694
  const { username, password, setUsername, setPassword } = useLoginPrefill({
635
695
  initialUsername,
636
696
  initialPassword,
637
- prefillNonce
697
+ prefillNonce,
698
+ prefillIntent
699
+ });
700
+ const { errorText, handleSubmit } = useLoginSubmit({
701
+ username,
702
+ password,
703
+ login,
704
+ onSuccess,
705
+ missingFieldsLabel: labels.missingFields,
706
+ invalidCredentialsLabel: labels.invalidCredentials
638
707
  });
639
- const [errorText, setErrorText] = useState(null);
640
- const runLogin = useCallback(async () => {
641
- setErrorText(null);
642
- const trimmedUsername = username.trim();
643
- const hasMissingField = trimmedUsername.length === 0 || password.length === 0;
644
- if (hasMissingField) {
645
- setErrorText(labels.missingFields);
646
- return;
647
- }
648
- try {
649
- const user = await login({ username: trimmedUsername, password });
650
- onSuccess(user);
651
- } catch {
652
- setErrorText(labels.invalidCredentials);
653
- }
654
- }, [username, password, login, onSuccess, labels.missingFields, labels.invalidCredentials]);
655
- const handleSubmit = useCallback(() => {
656
- void runLogin();
657
- }, [runLogin]);
658
708
  const submitButtonStyle = isSubmitting ? [styles3.primaryButton, styles3.primaryButtonDisabled] : styles3.primaryButton;
659
709
  const content = /* @__PURE__ */ jsxs(Fragment, { children: [
660
710
  /* @__PURE__ */ jsx(Text, { style: styles3.title, children: labels.title }),
@@ -3323,7 +3373,8 @@ var EMPTY_CONFIG = {
3323
3373
  hasPin: false,
3324
3374
  pinDigits: null,
3325
3375
  preferredMethod: null
3326
- }
3376
+ },
3377
+ demo: null
3327
3378
  };
3328
3379
  function useBffLoginConfig(client) {
3329
3380
  const [config, setConfig] = useState(EMPTY_CONFIG);
@@ -3420,6 +3471,12 @@ async function syncPreferredMethodFromServer(client) {
3420
3471
  return null;
3421
3472
  }
3422
3473
  }
3474
+ function isSamePair(a, b) {
3475
+ if (a === null || b === null) {
3476
+ return a === b;
3477
+ }
3478
+ return a.username === b.username && a.password === b.password;
3479
+ }
3423
3480
  function useDemoCredentials({
3424
3481
  credentials,
3425
3482
  prefillOnMount = false
@@ -3429,23 +3486,38 @@ function useDemoCredentials({
3429
3486
  prefillOnMount ? resolved : null
3430
3487
  );
3431
3488
  const [prefillNonce, setPrefillNonce] = useState(0);
3489
+ const [prefillIntent, setPrefillIntent] = useState(
3490
+ "opportunistic" /* Opportunistic */
3491
+ );
3492
+ const [autoSeeded, setAutoSeeded] = useState(
3493
+ prefillOnMount ? resolved : null
3494
+ );
3495
+ const shouldAutoSeed = prefillOnMount && resolved !== null && !isSamePair(resolved, autoSeeded);
3496
+ if (shouldAutoSeed) {
3497
+ setAutoSeeded(resolved);
3498
+ setFilled(resolved);
3499
+ setPrefillNonce((current) => current + 1);
3500
+ setPrefillIntent("opportunistic" /* Opportunistic */);
3501
+ }
3432
3502
  const handleUse = useCallback((next) => {
3433
3503
  setFilled(next);
3434
3504
  setPrefillNonce((current) => current + 1);
3505
+ setPrefillIntent("explicit" /* Explicit */);
3435
3506
  }, []);
3436
3507
  return useMemo(
3437
3508
  () => ({
3438
3509
  loginFormProps: {
3439
3510
  initialUsername: filled?.username,
3440
3511
  initialPassword: filled?.password,
3441
- prefillNonce
3512
+ prefillNonce,
3513
+ prefillIntent
3442
3514
  },
3443
3515
  // `credentials` is passed through unresolved on purpose: the hint applies
3444
3516
  // `resolveDemoCredentials` itself, so it fails closed even when it is used
3445
3517
  // standalone, without this hook.
3446
3518
  hintProps: { credentials, onUse: handleUse }
3447
3519
  }),
3448
- [filled, prefillNonce, credentials, handleUse]
3520
+ [filled, prefillNonce, prefillIntent, credentials, handleUse]
3449
3521
  );
3450
3522
  }
3451
3523
  async function lazyFetchHttpClient(request) {
@@ -3534,6 +3606,6 @@ async function performBffLogout(options) {
3534
3606
  runGuarded(onRedirect, onError);
3535
3607
  }
3536
3608
 
3537
- export { AuthScreen, AuthTestIds, AuthThemeProvider, BffAuthStatus, DEFAULT_AUTH_CARD_MAX_WIDTH, DEFAULT_DEMO_CREDENTIALS_HINT_LABELS, DEFAULT_DEVICE_PIN_ENROLL_LABELS, DEFAULT_DEVICE_PIN_SETTINGS_LABELS, DEFAULT_DEVICE_PIN_UNLOCK_LABELS, DEFAULT_FORGOT_PASSWORD_FIELDS_LABELS, DEFAULT_FORGOT_PASSWORD_LABELS, DEFAULT_LOGIN_LABELS, DEFAULT_OTP_LABELS, DEFAULT_PASSKEY_LOGIN_LABELS, DEFAULT_PASSKEY_SETTINGS_LABELS, DEFAULT_PIN_LABELS, DEFAULT_PREFERRED_METHOD_HINT_LABELS, DEFAULT_PREFERRED_METHOD_SETTINGS_LABELS, DEFAULT_RESET_PASSWORD_LABELS, DEVICE_PIN_ALLOWED_DIGITS, DEVICE_PIN_DEFAULT_DIGITS, DemoCredentialsHint, DevicePinEnrollErrorKey, DevicePinEnrollForm, DevicePinErrorKey, DevicePinInput, DevicePinLengthPicker, DevicePinOffer, DevicePinSettingsCard, DevicePinUnlockScreen, ForgotPasswordFields, ForgotPasswordForm, LoginForm, OtpForm, OtpLoginStep, PASSWORD_MAX_LENGTH, PASSWORD_MIN_LENGTH, PasskeyCeremonyMode, PasskeyCeremonyStatus, PasskeyLoginButton, PasskeySettingsCard, PasswordPolicyError, PinForm, PreferredMethodHint, PreferredMethodSettingsCard, ResetPasswordError, ResetPasswordForm, cachePreferredMethod, clearCachedPreferredMethod, collectUserRoles, createBffAuthClient, createPreferencesClient, defaultAuthTheme, isAllowedPinDigits, isPasswordValid, isValidForgotPasswordEmail, performBffLogout, readCachedPreferredMethod, readPasskeyError, readPasskeyRegistered, resolveAccessibleRoutes, resolveDemoCredentials, resolvePostLoginRoute, startPasskeyLogin, startPasskeyRegistration, syncPreferredMethodFromServer, useAuthTheme, useBffAuth, useBffForgotPassword, useBffLoginConfig, useBffResetPassword, useDemoCredentials, useDevicePinDisable, useDevicePinEnroll, useDevicePinUnlock, useForgotPasswordSubmit, useOtpLogin, usePasskeyCeremony, usePinLogin, usePreferredMethodSetting, useResetPasswordForm, validatePasswordPolicy, withTestIdPrefix };
3609
+ export { AuthScreen, AuthTestIds, AuthThemeProvider, BffAuthStatus, DEFAULT_AUTH_CARD_MAX_WIDTH, DEFAULT_DEMO_CREDENTIALS_HINT_LABELS, DEFAULT_DEVICE_PIN_ENROLL_LABELS, DEFAULT_DEVICE_PIN_SETTINGS_LABELS, DEFAULT_DEVICE_PIN_UNLOCK_LABELS, DEFAULT_FORGOT_PASSWORD_FIELDS_LABELS, DEFAULT_FORGOT_PASSWORD_LABELS, DEFAULT_LOGIN_LABELS, DEFAULT_OTP_LABELS, DEFAULT_PASSKEY_LOGIN_LABELS, DEFAULT_PASSKEY_SETTINGS_LABELS, DEFAULT_PIN_LABELS, DEFAULT_PREFERRED_METHOD_HINT_LABELS, DEFAULT_PREFERRED_METHOD_SETTINGS_LABELS, DEFAULT_RESET_PASSWORD_LABELS, DEVICE_PIN_ALLOWED_DIGITS, DEVICE_PIN_DEFAULT_DIGITS, DemoCredentialsHint, DevicePinEnrollErrorKey, DevicePinEnrollForm, DevicePinErrorKey, DevicePinInput, DevicePinLengthPicker, DevicePinOffer, DevicePinSettingsCard, DevicePinUnlockScreen, ForgotPasswordFields, ForgotPasswordForm, LoginForm, OtpForm, OtpLoginStep, PASSWORD_MAX_LENGTH, PASSWORD_MIN_LENGTH, PasskeyCeremonyMode, PasskeyCeremonyStatus, PasskeyLoginButton, PasskeySettingsCard, PasswordPolicyError, PinForm, PreferredMethodHint, PreferredMethodSettingsCard, PrefillIntent, ResetPasswordError, ResetPasswordForm, cachePreferredMethod, clearCachedPreferredMethod, collectUserRoles, createBffAuthClient, createPreferencesClient, defaultAuthTheme, isAllowedPinDigits, isPasswordValid, isValidForgotPasswordEmail, performBffLogout, readCachedPreferredMethod, readPasskeyError, readPasskeyRegistered, resolveAccessibleRoutes, resolveDemoCredentials, resolvePostLoginRoute, startPasskeyLogin, startPasskeyRegistration, syncPreferredMethodFromServer, useAuthTheme, useBffAuth, useBffForgotPassword, useBffLoginConfig, useBffResetPassword, useDemoCredentials, useDevicePinDisable, useDevicePinEnroll, useDevicePinUnlock, useForgotPasswordSubmit, useOtpLogin, usePasskeyCeremony, usePinLogin, usePreferredMethodSetting, useResetPasswordForm, validatePasswordPolicy, withTestIdPrefix };
3538
3610
  //# sourceMappingURL=index.mjs.map
3539
3611
  //# sourceMappingURL=index.mjs.map