@passkeyme/react-auth 2.2.3 → 2.2.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/index.js CHANGED
@@ -6474,7 +6474,8 @@ const PasskeymeCallbackHandler = ({ loadingComponent: LoadingComponent, errorCom
6474
6474
  authenticatedUser: null,
6475
6475
  });
6476
6476
  // Track if we've already processed the callback to prevent loops
6477
- const [callbackProcessed, setCallbackProcessed] = React.useState(false);
6477
+ // Using useRef instead of useState to avoid triggering re-renders when marked as processed
6478
+ const callbackProcessedRef = React.useRef(false);
6478
6479
  // Get effective passkey configuration (merge config with props)
6479
6480
  const effectivePasskeyConfig = {
6480
6481
  promptRegistration: (_d = (_b = (_a = passkey === null || passkey === void 0 ? void 0 : passkey.promptRegistration) !== null && _a !== void 0 ? _a : config.autoPromptPasskeyRegistration) !== null && _b !== void 0 ? _b : (_c = config.passkey) === null || _c === void 0 ? void 0 : _c.autoPromptRegistration) !== null && _d !== void 0 ? _d : true, // Default to true
@@ -6686,6 +6687,8 @@ const PasskeymeCallbackHandler = ({ loadingComponent: LoadingComponent, errorCom
6686
6687
  };
6687
6688
  // Proceed with redirect after auth completion
6688
6689
  const proceedWithRedirect = async () => {
6690
+ // Clean URL immediately to prevent effect re-run with stale URL params
6691
+ window.history.replaceState({}, document.title, window.location.pathname);
6689
6692
  setTimeout(async () => {
6690
6693
  const currentUser = state.authenticatedUser || user;
6691
6694
  if (onSuccess && currentUser) {
@@ -6700,15 +6703,14 @@ const PasskeymeCallbackHandler = ({ loadingComponent: LoadingComponent, errorCom
6700
6703
  }
6701
6704
  }
6702
6705
  else {
6703
- // Clean URL and redirect to success page
6704
- window.history.replaceState({}, document.title, window.location.pathname);
6706
+ // Redirect to success page
6705
6707
  window.location.href = successRedirect;
6706
6708
  }
6707
6709
  }, 100);
6708
6710
  };
6709
6711
  React.useEffect(() => {
6710
6712
  // Don't process callback again if we've already done it
6711
- if (callbackProcessed)
6713
+ if (callbackProcessedRef.current)
6712
6714
  return;
6713
6715
  const processCallback = async () => {
6714
6716
  try {
@@ -6728,7 +6730,7 @@ const PasskeymeCallbackHandler = ({ loadingComponent: LoadingComponent, errorCom
6728
6730
  if (error) {
6729
6731
  const errorMessage = errorDescription || error || "Authentication failed";
6730
6732
  updateState({ loading: false, error: errorMessage, success: false });
6731
- setCallbackProcessed(true);
6733
+ callbackProcessedRef.current = true;
6732
6734
  if (onError) {
6733
6735
  onError(errorMessage);
6734
6736
  }
@@ -6767,7 +6769,7 @@ const PasskeymeCallbackHandler = ({ loadingComponent: LoadingComponent, errorCom
6767
6769
  });
6768
6770
  debugLog(config, "CallbackHandler", "Token flow - updated state, showPasskeyPrompt:", shouldPrompt);
6769
6771
  // Mark callback as processed to prevent re-execution
6770
- setCallbackProcessed(true);
6772
+ callbackProcessedRef.current = true;
6771
6773
  if (!shouldPrompt) {
6772
6774
  // Proceed with normal redirect
6773
6775
  proceedWithRedirect();
@@ -6780,7 +6782,7 @@ const PasskeymeCallbackHandler = ({ loadingComponent: LoadingComponent, errorCom
6780
6782
  error: errorMessage,
6781
6783
  success: false,
6782
6784
  });
6783
- setCallbackProcessed(true);
6785
+ callbackProcessedRef.current = true;
6784
6786
  if (onError) {
6785
6787
  onError(errorMessage);
6786
6788
  }
@@ -6818,7 +6820,7 @@ const PasskeymeCallbackHandler = ({ loadingComponent: LoadingComponent, errorCom
6818
6820
  });
6819
6821
  debugLog(config, "CallbackHandler", "OAuth code flow - updated state, showPasskeyPrompt:", shouldPrompt);
6820
6822
  // Mark callback as processed to prevent re-execution
6821
- setCallbackProcessed(true);
6823
+ callbackProcessedRef.current = true;
6822
6824
  if (!shouldPrompt) {
6823
6825
  // Proceed with normal redirect
6824
6826
  proceedWithRedirect();
@@ -6831,7 +6833,7 @@ const PasskeymeCallbackHandler = ({ loadingComponent: LoadingComponent, errorCom
6831
6833
  error: errorMessage,
6832
6834
  success: false,
6833
6835
  });
6834
- setCallbackProcessed(true);
6836
+ callbackProcessedRef.current = true;
6835
6837
  if (onError) {
6836
6838
  onError(errorMessage);
6837
6839
  }
@@ -6849,7 +6851,7 @@ const PasskeymeCallbackHandler = ({ loadingComponent: LoadingComponent, errorCom
6849
6851
  if (!token && !code) {
6850
6852
  const errorMessage = "No authentication token or code received";
6851
6853
  updateState({ loading: false, error: errorMessage, success: false });
6852
- setCallbackProcessed(true);
6854
+ callbackProcessedRef.current = true;
6853
6855
  if (onError) {
6854
6856
  onError(errorMessage);
6855
6857
  }
@@ -6862,12 +6864,12 @@ const PasskeymeCallbackHandler = ({ loadingComponent: LoadingComponent, errorCom
6862
6864
  }
6863
6865
  }
6864
6866
  // Mark as processed if we got here
6865
- setCallbackProcessed(true);
6867
+ callbackProcessedRef.current = true;
6866
6868
  }
6867
6869
  catch (err) {
6868
6870
  const errorMessage = err instanceof Error ? err.message : "Authentication failed";
6869
6871
  updateState({ loading: false, error: errorMessage, success: false });
6870
- setCallbackProcessed(true);
6872
+ callbackProcessedRef.current = true;
6871
6873
  if (onError) {
6872
6874
  onError(errorMessage);
6873
6875
  }
@@ -6882,7 +6884,6 @@ const PasskeymeCallbackHandler = ({ loadingComponent: LoadingComponent, errorCom
6882
6884
  };
6883
6885
  processCallback();
6884
6886
  }, [
6885
- callbackProcessed,
6886
6887
  handleCallback,
6887
6888
  handleTokenCallback,
6888
6889
  onError,