@dloizides/auth-web 1.8.1 → 1.9.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
@@ -235,7 +235,8 @@ var DEFAULT_PASSKEY_LOGIN_LABELS = {
235
235
  signInButton: "Sign in with a passkey",
236
236
  signInHint: "Use your fingerprint, face, or security key to sign in",
237
237
  errorCancelled: "Passkey sign-in was cancelled. You can try again or sign in another way.",
238
- errorFailed: "Passkey sign-in didn't work. Try again, or sign in another way."
238
+ errorFailed: "Passkey sign-in didn't work. Try again, or sign in another way.",
239
+ tryAnotherWay: "Sign in another way"
239
240
  };
240
241
  var DEFAULT_PASSKEY_SETTINGS_LABELS = {
241
242
  title: "Passkeys",
@@ -337,6 +338,7 @@ var AuthTestIds = {
337
338
  passkeyLogin: "auth-passkey-login",
338
339
  passkeyLoginButton: "auth-passkey-login-button",
339
340
  passkeyLoginError: "auth-passkey-login-error",
341
+ passkeyLoginFallback: "auth-passkey-login-fallback",
340
342
  // Passkey settings card
341
343
  passkeySettings: "auth-passkey-settings",
342
344
  passkeySettingsAdd: "auth-passkey-settings-add",
@@ -2517,6 +2519,18 @@ var PasskeyCeremonyMode = /* @__PURE__ */ ((PasskeyCeremonyMode2) => {
2517
2519
  return PasskeyCeremonyMode2;
2518
2520
  })(PasskeyCeremonyMode || {});
2519
2521
 
2522
+ // src/passkey/browserLocation.ts
2523
+ function getBrowserLocation() {
2524
+ if (typeof window === "undefined") {
2525
+ return null;
2526
+ }
2527
+ const browserLocation = window.location;
2528
+ if (browserLocation === void 0) {
2529
+ return null;
2530
+ }
2531
+ return browserLocation;
2532
+ }
2533
+
2520
2534
  // src/passkey/passkeyNavigation.ts
2521
2535
  var PASSKEY_LOGIN_ENDPOINT = "/bff/passkey/login";
2522
2536
  var PASSKEY_REGISTER_ENDPOINT = "/bff/passkey/register";
@@ -2530,22 +2544,25 @@ function buildNavigationUrl(endpoint, returnUrl) {
2530
2544
  return `${endpoint}?${RETURN_URL_PARAM}=${encodeURIComponent(returnUrl)}`;
2531
2545
  }
2532
2546
  function readSearchParams() {
2533
- if (typeof window === "undefined") {
2547
+ const browserLocation = getBrowserLocation();
2548
+ if (browserLocation === null) {
2534
2549
  return null;
2535
2550
  }
2536
- return new URLSearchParams(window.location.search);
2551
+ return new URLSearchParams(browserLocation.search);
2537
2552
  }
2538
2553
  function startPasskeyLogin(returnUrl) {
2539
- if (typeof window === "undefined") {
2554
+ const browserLocation = getBrowserLocation();
2555
+ if (browserLocation === null) {
2540
2556
  return;
2541
2557
  }
2542
- window.location.assign(buildNavigationUrl(PASSKEY_LOGIN_ENDPOINT, returnUrl));
2558
+ browserLocation.assign(buildNavigationUrl(PASSKEY_LOGIN_ENDPOINT, returnUrl));
2543
2559
  }
2544
2560
  function startPasskeyRegistration(returnUrl) {
2545
- if (typeof window === "undefined") {
2561
+ const browserLocation = getBrowserLocation();
2562
+ if (browserLocation === null) {
2546
2563
  return;
2547
2564
  }
2548
- window.location.assign(buildNavigationUrl(PASSKEY_REGISTER_ENDPOINT, returnUrl));
2565
+ browserLocation.assign(buildNavigationUrl(PASSKEY_REGISTER_ENDPOINT, returnUrl));
2549
2566
  }
2550
2567
  function readPasskeyError() {
2551
2568
  const params = readSearchParams();
@@ -2722,8 +2739,9 @@ function usePasskeyCeremony(optionsArg) {
2722
2739
  onSuccess(user);
2723
2740
  return;
2724
2741
  }
2725
- if (mode === "login" /* Login */ && typeof window !== "undefined") {
2726
- window.location.assign(returnUrl);
2742
+ const browserLocation = getBrowserLocation();
2743
+ if (mode === "login" /* Login */ && browserLocation !== null) {
2744
+ browserLocation.assign(returnUrl);
2727
2745
  }
2728
2746
  },
2729
2747
  [mode, onSuccess, returnUrl]
@@ -2745,6 +2763,10 @@ function usePasskeyCeremony(optionsArg) {
2745
2763
  const envelope = await optionsResponse.json();
2746
2764
  const credential = await runCeremony(mode, envelope);
2747
2765
  if (credential === null) {
2766
+ if (mode === "login" /* Login */) {
2767
+ redirectFallback(mode, returnUrl);
2768
+ return;
2769
+ }
2748
2770
  setStatus("error" /* Error */);
2749
2771
  setError(ERROR_FAILED);
2750
2772
  return;
@@ -2776,13 +2798,16 @@ function usePasskeyCeremony(optionsArg) {
2776
2798
  }
2777
2799
  })();
2778
2800
  }, [isSupported, mode, returnUrl, succeed]);
2801
+ const fallbackToRedirect = useCallback(() => {
2802
+ redirectFallback(mode, returnUrl);
2803
+ }, [mode, returnUrl]);
2779
2804
  const reset = useCallback(() => {
2780
2805
  setStatus("idle" /* Idle */);
2781
2806
  setError(null);
2782
2807
  }, []);
2783
2808
  return useMemo(
2784
- () => ({ status, error, isSupported, start, reset }),
2785
- [status, error, isSupported, start, reset]
2809
+ () => ({ status, error, isSupported, start, fallbackToRedirect, reset }),
2810
+ [status, error, isSupported, start, fallbackToRedirect, reset]
2786
2811
  );
2787
2812
  }
2788
2813
  var DEFAULT_RETURN_URL = "/";
@@ -2801,14 +2826,27 @@ function PasskeyLoginButton({
2801
2826
  const ceremony = usePasskeyCeremony({ mode: "login" /* Login */, returnUrl });
2802
2827
  const error = ceremony.error ?? readPasskeyError();
2803
2828
  return /* @__PURE__ */ jsxs(View, { testID: withTestIdPrefix(AuthTestIds.passkeyLogin, testIdPrefix), children: [
2804
- error !== null ? /* @__PURE__ */ jsx(
2805
- Text,
2806
- {
2807
- style: styles3.errorText,
2808
- testID: withTestIdPrefix(AuthTestIds.passkeyLoginError, testIdPrefix),
2809
- children: error === "cancelled" ? labels.errorCancelled : labels.errorFailed
2810
- }
2811
- ) : null,
2829
+ error !== null ? /* @__PURE__ */ jsxs(Fragment, { children: [
2830
+ /* @__PURE__ */ jsx(
2831
+ Text,
2832
+ {
2833
+ style: styles3.errorText,
2834
+ testID: withTestIdPrefix(AuthTestIds.passkeyLoginError, testIdPrefix),
2835
+ children: error === "cancelled" ? labels.errorCancelled : labels.errorFailed
2836
+ }
2837
+ ),
2838
+ /* @__PURE__ */ jsx(
2839
+ TouchableOpacity,
2840
+ {
2841
+ accessibilityHint: labels.tryAnotherWay,
2842
+ accessibilityLabel: labels.tryAnotherWay,
2843
+ accessibilityRole: "button",
2844
+ testID: withTestIdPrefix(AuthTestIds.passkeyLoginFallback, testIdPrefix),
2845
+ onPress: () => ceremony.fallbackToRedirect(),
2846
+ children: /* @__PURE__ */ jsx(Text, { style: styles3.linkText, children: labels.tryAnotherWay })
2847
+ }
2848
+ )
2849
+ ] }) : null,
2812
2850
  /* @__PURE__ */ jsx(
2813
2851
  TouchableOpacity,
2814
2852
  {
@@ -2825,10 +2863,11 @@ function PasskeyLoginButton({
2825
2863
  }
2826
2864
  var DEFAULT_RETURN_PATH = "/";
2827
2865
  function readCurrentPath() {
2828
- if (typeof window === "undefined") {
2866
+ const browserLocation = getBrowserLocation();
2867
+ if (browserLocation === null) {
2829
2868
  return DEFAULT_RETURN_PATH;
2830
2869
  }
2831
- return window.location.pathname;
2870
+ return browserLocation.pathname;
2832
2871
  }
2833
2872
  function PasskeySettingsCard({
2834
2873
  returnUrl,