@forge-connect/react 1.0.0 → 1.0.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.cjs CHANGED
@@ -402,33 +402,13 @@ function createApiClient(apiUrl) {
402
402
  }
403
403
 
404
404
  // src/utils.ts
405
- var TOKEN_KEY = "fc_access_token";
406
- function getStoredToken() {
407
- try {
408
- return localStorage.getItem(TOKEN_KEY);
409
- } catch (e4) {
410
- return null;
411
- }
412
- }
413
- function setStoredToken(token) {
414
- try {
415
- localStorage.setItem(TOKEN_KEY, token);
416
- } catch (e5) {
417
- }
418
- }
419
- function removeStoredToken() {
420
- try {
421
- localStorage.removeItem(TOKEN_KEY);
422
- } catch (e6) {
423
- }
424
- }
425
405
  function decodeJWT(token) {
426
406
  try {
427
407
  const parts = token.split(".");
428
408
  if (parts.length !== 3) return null;
429
409
  const payload = JSON.parse(atob(parts[1].replace(/-/g, "+").replace(/_/g, "/")));
430
410
  return payload;
431
- } catch (e7) {
411
+ } catch (e4) {
432
412
  return null;
433
413
  }
434
414
  }
@@ -1759,7 +1739,7 @@ function SvgIcon({ svg, className }) {
1759
1739
  });
1760
1740
  ref.current.textContent = "";
1761
1741
  ref.current.appendChild(svgEl);
1762
- } catch (e8) {
1742
+ } catch (e5) {
1763
1743
  ref.current.textContent = "";
1764
1744
  }
1765
1745
  }, [svg]);
@@ -2519,7 +2499,7 @@ function PasskeysModal({ isOpen, onClose, onCountChange }) {
2519
2499
  const list = await api.getPasskeys(token);
2520
2500
  setPasskeys(list);
2521
2501
  onCountChange(list.length);
2522
- } catch (e9) {
2502
+ } catch (e6) {
2523
2503
  } finally {
2524
2504
  setLoading(false);
2525
2505
  }
@@ -3748,42 +3728,22 @@ function ForgeConnectProvider({ config, children, onLogin, onLogout, walletAdapt
3748
3728
  refreshTimerRef.current = setTimeout(async () => {
3749
3729
  try {
3750
3730
  const { accessToken } = await api.refresh();
3751
- setStoredToken(accessToken);
3752
3731
  setAuth((prev) => ({ ...prev, accessToken }));
3753
3732
  scheduleRefresh(accessToken);
3754
- } catch (e10) {
3755
- removeStoredToken();
3733
+ } catch (e7) {
3756
3734
  setAuth({ status: "unauthenticated", user: null, accessToken: null });
3757
3735
  }
3758
3736
  }, delay);
3759
3737
  }, [api]);
3760
3738
  _react.useEffect.call(void 0, () => {
3761
3739
  const init = async () => {
3762
- const token = getStoredToken();
3763
- if (!token) {
3764
- setAuth({ status: "unauthenticated", user: null, accessToken: null });
3765
- return;
3766
- }
3767
3740
  try {
3768
- const user = await api.getMe(token);
3769
- setAuth({ status: "authenticated", user, accessToken: token });
3770
- scheduleRefresh(token);
3771
- } catch (err) {
3772
- if (err instanceof ForgeConnectApiError && err.status === 401) {
3773
- try {
3774
- const { accessToken } = await api.refresh();
3775
- const user = await api.getMe(accessToken);
3776
- setStoredToken(accessToken);
3777
- setAuth({ status: "authenticated", user, accessToken });
3778
- scheduleRefresh(accessToken);
3779
- } catch (e11) {
3780
- removeStoredToken();
3781
- setAuth({ status: "unauthenticated", user: null, accessToken: null });
3782
- }
3783
- } else {
3784
- removeStoredToken();
3785
- setAuth({ status: "unauthenticated", user: null, accessToken: null });
3786
- }
3741
+ const { accessToken } = await api.refresh();
3742
+ const user = await api.getMe(accessToken);
3743
+ setAuth({ status: "authenticated", user, accessToken });
3744
+ scheduleRefresh(accessToken);
3745
+ } catch (e8) {
3746
+ setAuth({ status: "unauthenticated", user: null, accessToken: null });
3787
3747
  }
3788
3748
  };
3789
3749
  init();
@@ -3826,7 +3786,6 @@ function ForgeConnectProvider({ config, children, onLogin, onLogout, walletAdapt
3826
3786
  }
3827
3787
  const token = result.accessToken;
3828
3788
  if (!token) return;
3829
- setStoredToken(token);
3830
3789
  setModal({ isOpen: true, step: "success" });
3831
3790
  const user = await api.getMe(token);
3832
3791
  setAuth({ status: "authenticated", user, accessToken: token });
@@ -3835,8 +3794,7 @@ function ForgeConnectProvider({ config, children, onLogin, onLogout, walletAdapt
3835
3794
  setTimeout(() => {
3836
3795
  setModal({ isOpen: false, step: "method-select" });
3837
3796
  }, 1500);
3838
- } catch (e12) {
3839
- removeStoredToken();
3797
+ } catch (e9) {
3840
3798
  }
3841
3799
  };
3842
3800
  window.addEventListener("message", handleMessage);
@@ -3854,7 +3812,6 @@ function ForgeConnectProvider({ config, children, onLogin, onLogout, walletAdapt
3854
3812
  }, []);
3855
3813
  const handleAuthSuccess = _react.useCallback.call(void 0,
3856
3814
  async (token) => {
3857
- setStoredToken(token);
3858
3815
  const user = await api.getMe(token);
3859
3816
  setAuth({ status: "authenticated", user, accessToken: token });
3860
3817
  scheduleRefresh(token);
@@ -3957,14 +3914,13 @@ function ForgeConnectProvider({ config, children, onLogin, onLogout, walletAdapt
3957
3914
  );
3958
3915
  const logout = _react.useCallback.call(void 0, async () => {
3959
3916
  const token = auth.accessToken;
3960
- removeStoredToken();
3961
3917
  if (refreshTimerRef.current) clearTimeout(refreshTimerRef.current);
3962
3918
  setAuth({ status: "unauthenticated", user: null, accessToken: null });
3963
3919
  _optionalChain([onLogout, 'optionalCall', _119 => _119()]);
3964
3920
  if (token) {
3965
3921
  try {
3966
3922
  await api.logout(token);
3967
- } catch (e13) {
3923
+ } catch (e10) {
3968
3924
  }
3969
3925
  }
3970
3926
  }, [auth.accessToken, api, onLogout]);
@@ -4012,14 +3968,13 @@ function ForgeConnectProvider({ config, children, onLogin, onLogout, walletAdapt
4012
3968
  }, [api, challengeToken, handleAuthSuccess]);
4013
3969
  const logoutAll = _react.useCallback.call(void 0, async () => {
4014
3970
  const token = auth.accessToken;
4015
- removeStoredToken();
4016
3971
  if (refreshTimerRef.current) clearTimeout(refreshTimerRef.current);
4017
3972
  setAuth({ status: "unauthenticated", user: null, accessToken: null });
4018
3973
  _optionalChain([onLogout, 'optionalCall', _120 => _120()]);
4019
3974
  if (token) {
4020
3975
  try {
4021
3976
  await api.logoutAll(token);
4022
- } catch (e14) {
3977
+ } catch (e11) {
4023
3978
  }
4024
3979
  }
4025
3980
  }, [auth.accessToken, api, onLogout]);