fix: remove timeout for deleting lastOnline store
Signed-off-by: Juan Escalada <juanescalada175@gmail.com>
This commit is contained in:
@@ -231,27 +231,15 @@ const parseConfig = (
|
||||
export const AutoLogout = (props: AutoLogoutProps): JSX.Element | null => {
|
||||
const identityApi = useApi(identityApiRef);
|
||||
const configApi = useApi(configApiRef);
|
||||
const isLoggedRef = useRef<boolean | null>(null);
|
||||
const [isLogged, setIsLogged] = useState<boolean | null>(null);
|
||||
const lastSeenOnlineStore: TimestampStore = useMemo(
|
||||
() => new DefaultTimestampStore(LAST_SEEN_ONLINE_STORAGE_KEY),
|
||||
[],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
isLoggedRef.current = isLogged;
|
||||
}, [isLogged]);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
|
||||
const timeoutId = setTimeout(() => {
|
||||
if (cancelled) return;
|
||||
if (isLoggedRef.current === null || isLoggedRef.current === false) {
|
||||
lastSeenOnlineStore.delete();
|
||||
}
|
||||
}, 3000);
|
||||
|
||||
async function checkLogin(identity: IdentityApi) {
|
||||
try {
|
||||
const creds = await identity.getCredentials();
|
||||
@@ -272,7 +260,6 @@ export const AutoLogout = (props: AutoLogoutProps): JSX.Element | null => {
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
clearTimeout(timeoutId);
|
||||
};
|
||||
}, [lastSeenOnlineStore, identityApi]);
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ describe('useLogoutDisconnectedUserEffect', () => {
|
||||
renderHook(() => useLogoutDisconnectedUserEffect(props));
|
||||
|
||||
expect(mockTimestampStore.get).not.toHaveBeenCalled();
|
||||
expect(mockTimestampStore.delete).not.toHaveBeenCalled();
|
||||
expect(mockTimestampStore.save).not.toHaveBeenCalled();
|
||||
expect(mockIdentityApi.signOut).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user