@navservice/usuario 1.54.0 → 1.57.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
|
}
|
|
@@ -8578,7 +8546,7 @@ function Profile({ isCollapsed = false }) {
|
|
|
8578
8546
|
});
|
|
8579
8547
|
}
|
|
8580
8548
|
const NavBar = ()=>/*#__PURE__*/ jsxs("nav", {
|
|
8581
|
-
className: "
|
|
8549
|
+
className: " relative z-40 h-16 w-full shrink-0 flex items-center justify-between px-4 md:px-6 bg-theme-card/80 text-theme-text border-b border-theme-border backdrop-blur-xl shadow-sm ",
|
|
8582
8550
|
children: [
|
|
8583
8551
|
/*#__PURE__*/ jsx("div", {
|
|
8584
8552
|
className: "flex items-center gap-3",
|
|
@@ -8595,19 +8563,14 @@ const NavBar = ()=>/*#__PURE__*/ jsxs("nav", {
|
|
|
8595
8563
|
const layout_NavBar = NavBar;
|
|
8596
8564
|
function Layout() {
|
|
8597
8565
|
return /*#__PURE__*/ jsxs("div", {
|
|
8598
|
-
className: "w-full h-[100dvh] bg-theme-bg text-theme-text",
|
|
8566
|
+
className: "flex flex-col w-full h-[100dvh] bg-theme-bg text-theme-text overflow-hidden",
|
|
8599
8567
|
children: [
|
|
8600
8568
|
/*#__PURE__*/ jsx(layout_NavBar, {}),
|
|
8601
8569
|
/*#__PURE__*/ jsx("main", {
|
|
8602
|
-
className: "
|
|
8603
|
-
children: /*#__PURE__*/
|
|
8604
|
-
className: "h-full
|
|
8605
|
-
children:
|
|
8606
|
-
/*#__PURE__*/ jsx("div", {
|
|
8607
|
-
className: "h-16 shrink-0"
|
|
8608
|
-
}),
|
|
8609
|
-
/*#__PURE__*/ jsx(Outlet, {})
|
|
8610
|
-
]
|
|
8570
|
+
className: "flex-1 overflow-y-auto overflow-x-hidden min-h-0 bg-theme-bg",
|
|
8571
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
8572
|
+
className: "min-h-full w-full flex flex-col",
|
|
8573
|
+
children: /*#__PURE__*/ jsx(Outlet, {})
|
|
8611
8574
|
})
|
|
8612
8575
|
})
|
|
8613
8576
|
]
|