@neog-cloud/neog-api-client 0.1.3 → 0.1.4
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 +29 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +29 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1389,6 +1389,8 @@ const getErrorMessage = (error, fallback = "Erro ao processar a requisição") =
|
|
|
1389
1389
|
return fallback;
|
|
1390
1390
|
};
|
|
1391
1391
|
|
|
1392
|
+
const USERINFO_ERROR_MESSAGE = "Nao foi possivel carregar dados do usuario";
|
|
1393
|
+
const USERINFO_RETRY_DELAY_MS = 500;
|
|
1392
1394
|
const resolveExpiresAt = (data) => {
|
|
1393
1395
|
if (data.expires_at)
|
|
1394
1396
|
return data.expires_at;
|
|
@@ -1467,6 +1469,14 @@ const createAuthProvider = (options) => {
|
|
|
1467
1469
|
return null;
|
|
1468
1470
|
}
|
|
1469
1471
|
};
|
|
1472
|
+
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
1473
|
+
const fetchUserInfoWithRetry = async (accessToken) => {
|
|
1474
|
+
const info = await fetchUserInfo(accessToken);
|
|
1475
|
+
if (info)
|
|
1476
|
+
return info;
|
|
1477
|
+
await wait(USERINFO_RETRY_DELAY_MS);
|
|
1478
|
+
return fetchUserInfo(accessToken);
|
|
1479
|
+
};
|
|
1470
1480
|
const refreshAccessToken = async () => {
|
|
1471
1481
|
if (!options.tokenRefreshEndpoint)
|
|
1472
1482
|
return null;
|
|
@@ -1594,9 +1604,16 @@ const createAuthProvider = (options) => {
|
|
|
1594
1604
|
let cancelled = false;
|
|
1595
1605
|
void (async () => {
|
|
1596
1606
|
var _a, _b;
|
|
1597
|
-
const info = await
|
|
1598
|
-
if (
|
|
1607
|
+
const info = await fetchUserInfoWithRetry(state.token);
|
|
1608
|
+
if (cancelled)
|
|
1609
|
+
return;
|
|
1610
|
+
if (!info) {
|
|
1611
|
+
handleLogout();
|
|
1612
|
+
if (isMounted.current) {
|
|
1613
|
+
setError(USERINFO_ERROR_MESSAGE);
|
|
1614
|
+
}
|
|
1599
1615
|
return;
|
|
1616
|
+
}
|
|
1600
1617
|
const nextState = {
|
|
1601
1618
|
token: authRef.current.token,
|
|
1602
1619
|
refreshToken: authRef.current.refreshToken,
|
|
@@ -1608,9 +1625,9 @@ const createAuthProvider = (options) => {
|
|
|
1608
1625
|
return () => {
|
|
1609
1626
|
cancelled = true;
|
|
1610
1627
|
};
|
|
1611
|
-
}, [state.token, state.user, syncState]);
|
|
1628
|
+
}, [state.token, state.user, syncState, handleLogout]);
|
|
1612
1629
|
const login = useCallback(async (username, password) => {
|
|
1613
|
-
var _a, _b
|
|
1630
|
+
var _a, _b;
|
|
1614
1631
|
setLoading(true);
|
|
1615
1632
|
setError(null);
|
|
1616
1633
|
try {
|
|
@@ -1644,8 +1661,13 @@ const createAuthProvider = (options) => {
|
|
|
1644
1661
|
const token = data.access_token;
|
|
1645
1662
|
const refreshToken = (_b = data.refresh_token) !== null && _b !== void 0 ? _b : null;
|
|
1646
1663
|
const expiresAt = resolveExpiresAt(data);
|
|
1647
|
-
const userInfo = token ? await
|
|
1648
|
-
|
|
1664
|
+
const userInfo = token ? await fetchUserInfoWithRetry(token) : null;
|
|
1665
|
+
if (token && !userInfo) {
|
|
1666
|
+
handleLogout();
|
|
1667
|
+
setError(USERINFO_ERROR_MESSAGE);
|
|
1668
|
+
throw new Error(USERINFO_ERROR_MESSAGE);
|
|
1669
|
+
}
|
|
1670
|
+
const user = userInfo !== null && userInfo !== void 0 ? userInfo : null;
|
|
1649
1671
|
const nextState = {
|
|
1650
1672
|
token,
|
|
1651
1673
|
refreshToken,
|
|
@@ -1674,6 +1696,7 @@ const createAuthProvider = (options) => {
|
|
|
1674
1696
|
authRequestFormat,
|
|
1675
1697
|
authGrantType,
|
|
1676
1698
|
authScope,
|
|
1699
|
+
handleLogout,
|
|
1677
1700
|
]);
|
|
1678
1701
|
const contextValue = useMemo(() => {
|
|
1679
1702
|
var _a, _b;
|