@swype-org/react-sdk 0.1.151 → 0.1.153

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.cjs CHANGED
@@ -3337,7 +3337,7 @@ function PasskeyScreen({
3337
3337
  }) {
3338
3338
  const { tokens } = useSwypeConfig();
3339
3339
  const handleCreate = popupFallback && onCreatePasskeyViaPopup ? onCreatePasskeyViaPopup : onCreatePasskey;
3340
- const buttonLabel = popupFallback ? "Open passkey window" : "Verify PassKey";
3340
+ const buttonLabel = popupFallback ? "Open Passkey Window" : "Verify Passkey";
3341
3341
  return /* @__PURE__ */ jsxRuntime.jsxs(
3342
3342
  ScreenLayout,
3343
3343
  {
@@ -6047,6 +6047,24 @@ function resolveRestoredMobileFlow(transferStatus, isSetup) {
6047
6047
  function usePasskeyHandlers(dispatch, apiBaseUrl, accounts, knownCredentialIds, mobileSetupFlowRef) {
6048
6048
  const { user, getAccessToken } = reactAuth.usePrivy();
6049
6049
  const checkingPasskeyRef = react.useRef(false);
6050
+ const activateExistingCredential = react.useCallback(async (credentialId) => {
6051
+ dispatch({ type: "PASSKEY_ACTIVATED", credentialId });
6052
+ window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, credentialId);
6053
+ const token = await getAccessToken();
6054
+ if (token) {
6055
+ reportPasskeyActivity(apiBaseUrl, token, credentialId).catch(() => {
6056
+ });
6057
+ }
6058
+ const resolved = resolvePostAuthStep({
6059
+ hasPasskey: true,
6060
+ accounts,
6061
+ persistedMobileFlow: loadMobileFlowState(),
6062
+ mobileSetupInProgress: mobileSetupFlowRef.current,
6063
+ connectingNewAccount: false
6064
+ });
6065
+ if (resolved.clearPersistedFlow) clearMobileFlowState();
6066
+ dispatch({ type: "NAVIGATE", step: resolved.step });
6067
+ }, [getAccessToken, apiBaseUrl, accounts, mobileSetupFlowRef, dispatch]);
6050
6068
  const completePasskeyRegistration = react.useCallback(async (credentialId, publicKey) => {
6051
6069
  const token = await getAccessToken();
6052
6070
  if (!token) throw new Error("Not authenticated");
@@ -6067,6 +6085,13 @@ function usePasskeyHandlers(dispatch, apiBaseUrl, accounts, knownCredentialIds,
6067
6085
  dispatch({ type: "SET_REGISTERING_PASSKEY", value: true });
6068
6086
  dispatch({ type: "SET_ERROR", error: null });
6069
6087
  try {
6088
+ if (knownCredentialIds.length > 0) {
6089
+ const matched = await findDevicePasskey(knownCredentialIds);
6090
+ if (matched) {
6091
+ await activateExistingCredential(matched);
6092
+ return;
6093
+ }
6094
+ }
6070
6095
  const passkeyDisplayName = user?.email?.address ?? user?.google?.name ?? user?.id ?? "Swype User";
6071
6096
  const { credentialId, publicKey } = await createPasskeyCredential({
6072
6097
  userId: user?.id ?? "unknown",
@@ -6086,12 +6111,29 @@ function usePasskeyHandlers(dispatch, apiBaseUrl, accounts, knownCredentialIds,
6086
6111
  } finally {
6087
6112
  dispatch({ type: "SET_REGISTERING_PASSKEY", value: false });
6088
6113
  }
6089
- }, [user, completePasskeyRegistration, dispatch]);
6114
+ }, [user, knownCredentialIds, activateExistingCredential, completePasskeyRegistration, dispatch]);
6090
6115
  const handleCreatePasskeyViaPopup = react.useCallback(async () => {
6091
6116
  dispatch({ type: "SET_REGISTERING_PASSKEY", value: true });
6092
6117
  dispatch({ type: "SET_ERROR", error: null });
6093
6118
  try {
6094
6119
  const token = await getAccessToken();
6120
+ if (knownCredentialIds.length > 0) {
6121
+ const directMatch = await findDevicePasskey(knownCredentialIds).catch(() => null);
6122
+ if (directMatch) {
6123
+ await activateExistingCredential(directMatch);
6124
+ return;
6125
+ }
6126
+ const popupMatch = await findDevicePasskeyViaPopup({
6127
+ credentialIds: knownCredentialIds,
6128
+ rpId: resolvePasskeyRpId(),
6129
+ authToken: token ?? void 0,
6130
+ apiBaseUrl
6131
+ });
6132
+ if (popupMatch) {
6133
+ await activateExistingCredential(popupMatch);
6134
+ return;
6135
+ }
6136
+ }
6095
6137
  const passkeyDisplayName = user?.email?.address ?? user?.google?.name ?? user?.id ?? "Swype User";
6096
6138
  const popupOptions = buildPasskeyPopupOptions({
6097
6139
  userId: user?.id ?? "unknown",
@@ -6120,7 +6162,7 @@ function usePasskeyHandlers(dispatch, apiBaseUrl, accounts, knownCredentialIds,
6120
6162
  } finally {
6121
6163
  dispatch({ type: "SET_REGISTERING_PASSKEY", value: false });
6122
6164
  }
6123
- }, [user, getAccessToken, apiBaseUrl, accounts, mobileSetupFlowRef, dispatch]);
6165
+ }, [user, knownCredentialIds, getAccessToken, apiBaseUrl, activateExistingCredential, accounts, mobileSetupFlowRef, dispatch]);
6124
6166
  const handleVerifyPasskeyViaPopup = react.useCallback(async () => {
6125
6167
  dispatch({ type: "SET_VERIFYING_PASSKEY", value: true });
6126
6168
  dispatch({ type: "SET_ERROR", error: null });