@navservice/usuario 1.54.0 → 1.56.0
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.
|
@@ -3,5 +3,5 @@ interface TypeRefreshToken {
|
|
|
3
3
|
app: TypesCore.Controller.Usuario.TokenPayload["app"];
|
|
4
4
|
usuario_tipo: TypesCore.Controller.Usuario.TokenPayload["usuario_tipo"];
|
|
5
5
|
}
|
|
6
|
-
export declare function RefreshToken(
|
|
6
|
+
export declare function RefreshToken({ app, usuario_tipo }: TypeRefreshToken): import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
export {};
|
package/build/es/index.js
CHANGED
|
@@ -7938,63 +7938,31 @@ const VerificarAuthenticator = ()=>{
|
|
|
7938
7938
|
});
|
|
7939
7939
|
};
|
|
7940
7940
|
const REFRESH_INTERVAL = 3300000;
|
|
7941
|
-
|
|
7942
|
-
const REFRESH_LOCK_KEY = "refresh_token_lock";
|
|
7943
|
-
const LOCK_DURATION = 10000;
|
|
7944
|
-
function RefreshToken_RefreshToken(props) {
|
|
7941
|
+
function RefreshToken_RefreshToken({ app, usuario_tipo }) {
|
|
7945
7942
|
const isRefreshingRef = useRef(false);
|
|
7946
|
-
const intervalRef = useRef(null);
|
|
7947
|
-
function getSafeTimestamp(key) {
|
|
7948
|
-
const value1 = src_utils.session_sorage.get_item_session_storage(key);
|
|
7949
|
-
return value1 && !isNaN(Number(value1)) ? Number(value1) : 0;
|
|
7950
|
-
}
|
|
7951
|
-
function setSafeTimestamp(key, value1) {
|
|
7952
|
-
src_utils.session_sorage.set_session_storage_sem_incremento({
|
|
7953
|
-
chave: key,
|
|
7954
|
-
novoItem: value1.toString()
|
|
7955
|
-
});
|
|
7956
|
-
}
|
|
7957
|
-
function checkAuthentication() {
|
|
7958
|
-
const usuario = src_utils.session_sorage.usuario_auth;
|
|
7959
|
-
if (!usuario?.data?.usuario?._id || !usuario?.data?.usuario?.refresh_token) {
|
|
7960
|
-
contexto_contexto_usuario.contexto.state.set_signout();
|
|
7961
|
-
return false;
|
|
7962
|
-
}
|
|
7963
|
-
return true;
|
|
7964
|
-
}
|
|
7965
7943
|
async function handleRefreshToken() {
|
|
7966
|
-
if (
|
|
7944
|
+
if (isRefreshingRef.current) return;
|
|
7945
|
+
const usuario = src_utils.session_sorage.usuario_auth?.data?.usuario;
|
|
7946
|
+
if (!usuario?._id || !usuario?.refresh_token) return void contexto_contexto_usuario.contexto.state.set_signout();
|
|
7947
|
+
isRefreshingRef.current = true;
|
|
7967
7948
|
try {
|
|
7968
|
-
|
|
7969
|
-
const now = Date.now();
|
|
7970
|
-
const lastRefresh = getSafeTimestamp(REFRESH_STORAGE_KEY);
|
|
7971
|
-
const lock = getSafeTimestamp(REFRESH_LOCK_KEY);
|
|
7972
|
-
if (lastRefresh && now - lastRefresh < REFRESH_INTERVAL) return;
|
|
7973
|
-
if (lock && now - lock < LOCK_DURATION) return;
|
|
7974
|
-
setSafeTimestamp(REFRESH_LOCK_KEY, now);
|
|
7975
|
-
isRefreshingRef.current = true;
|
|
7976
|
-
const response = await contexto_contexto_usuario.api.refresh_token({
|
|
7949
|
+
await contexto_contexto_usuario.api.refresh_token({
|
|
7977
7950
|
data: {
|
|
7978
7951
|
usuario: {
|
|
7979
|
-
app
|
|
7980
|
-
usuario_tipo
|
|
7952
|
+
app,
|
|
7953
|
+
usuario_tipo,
|
|
7981
7954
|
refresh_token: usuario.refresh_token
|
|
7982
7955
|
}
|
|
7983
7956
|
}
|
|
7984
7957
|
});
|
|
7985
|
-
if (response?.data?.status === 200) setSafeTimestamp(REFRESH_STORAGE_KEY, now);
|
|
7986
7958
|
} finally{
|
|
7987
7959
|
isRefreshingRef.current = false;
|
|
7988
|
-
setSafeTimestamp(REFRESH_LOCK_KEY, 0);
|
|
7989
7960
|
}
|
|
7990
7961
|
}
|
|
7991
7962
|
useEffect(()=>{
|
|
7992
|
-
if (!checkAuthentication()) return;
|
|
7993
7963
|
handleRefreshToken();
|
|
7994
|
-
|
|
7995
|
-
return ()=>
|
|
7996
|
-
if (intervalRef.current) clearInterval(intervalRef.current);
|
|
7997
|
-
};
|
|
7964
|
+
const interval = setInterval(handleRefreshToken, REFRESH_INTERVAL);
|
|
7965
|
+
return ()=>clearInterval(interval);
|
|
7998
7966
|
}, []);
|
|
7999
7967
|
return /*#__PURE__*/ jsx(Fragment, {});
|
|
8000
7968
|
}
|