Skip to content

Commit

Permalink
feat: [GSW-2040] Session Expired logout
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrg committed Jan 22, 2025
1 parent 2440f86 commit fa6e35c
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/web/src/hooks/common/use-auto-disconnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { useWallet } from "@hooks/wallet/data/use-wallet";
import { useAtom } from "jotai";
import { WalletState } from "@states/index";
import { useSessionExpiredModal } from "@hooks/wallet/ui/use-session-expired-modal";
import { useSocialWalletContext } from "./use-social-wallet-context";

const INACTIVITY_TIMEOUT_MS = 1 * 60 * 1000; // 5 minutes
const INACTIVITY_TIMEOUT_MS = 1 * 10 * 1000; // 5 minutes
const BACKGROUND_CHECK_INTERVAL = 10 * 1000;
const BACKGROUND_TIMEOUT_MS = 1 * 60 * 1000; // 5 minutes
const BACKGROUND_TIMEOUT_MS = 1 * 10 * 1000; // 5 minutes

const OPENLOGIN_STORE_KEY = "openlogin_store";

/**
*
Expand Down Expand Up @@ -43,7 +44,6 @@ export const useAutoDisconnect = () => {

const { openModal: openSessionExpiredModal } = useSessionExpiredModal();
const { account, disconnectWallet } = useWallet();
const { disconnect: disconnectSocialWallet } = useSocialWalletContext();

const inactivityTimerRef = React.useRef<NodeJS.Timeout>();
const backgroundCheckIntervalRef = React.useRef<NodeJS.Timeout>();
Expand All @@ -53,12 +53,11 @@ export const useAutoDisconnect = () => {
* Handles the wallet disconnection process
* Shows the sesion expired modal and disconnects the wallet
*/
const handleDisconnect = () => {
openSessionExpiredModal();
walletClient?.disconnect();
disconnectSocialWallet();
const handleDisconnect = React.useCallback(() => {
sessionStorage.removeItem(OPENLOGIN_STORE_KEY);
disconnectWallet();
};
openSessionExpiredModal();
}, [disconnectWallet, openSessionExpiredModal]);

/**
* Updates the last active timestamp and restarts the inactivity timer
Expand Down

0 comments on commit fa6e35c

Please sign in to comment.