@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 +13 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +6 -51
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -402,26 +402,6 @@ 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 {
|
|
410
|
-
return null;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
function setStoredToken(token) {
|
|
414
|
-
try {
|
|
415
|
-
localStorage.setItem(TOKEN_KEY, token);
|
|
416
|
-
} catch {
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
function removeStoredToken() {
|
|
420
|
-
try {
|
|
421
|
-
localStorage.removeItem(TOKEN_KEY);
|
|
422
|
-
} catch {
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
405
|
function decodeJWT(token) {
|
|
426
406
|
try {
|
|
427
407
|
const parts = token.split(".");
|
|
@@ -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
3733
|
} catch {
|
|
3755
|
-
removeStoredToken();
|
|
3756
3734
|
setAuth({ status: "unauthenticated", user: null, accessToken: null });
|
|
3757
3735
|
}
|
|
3758
3736
|
}, delay);
|
|
3759
3737
|
}, [api]);
|
|
3760
3738
|
useEffect12(() => {
|
|
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
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
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 {
|
|
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 {
|
|
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 });
|
|
@@ -3836,7 +3795,6 @@ function ForgeConnectProvider({ config, children, onLogin, onLogout, walletAdapt
|
|
|
3836
3795
|
setModal({ isOpen: false, step: "method-select" });
|
|
3837
3796
|
}, 1500);
|
|
3838
3797
|
} catch {
|
|
3839
|
-
removeStoredToken();
|
|
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 = useCallback8(
|
|
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,7 +3914,6 @@ function ForgeConnectProvider({ config, children, onLogin, onLogout, walletAdapt
|
|
|
3957
3914
|
);
|
|
3958
3915
|
const logout = useCallback8(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
|
onLogout?.();
|
|
@@ -4012,7 +3968,6 @@ function ForgeConnectProvider({ config, children, onLogin, onLogout, walletAdapt
|
|
|
4012
3968
|
}, [api, challengeToken, handleAuthSuccess]);
|
|
4013
3969
|
const logoutAll = useCallback8(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
|
onLogout?.();
|