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