Skip to content

Commit

Permalink
fix: sign out an expired session only if signed in
Browse files Browse the repository at this point in the history
  • Loading branch information
aramalipoor committed Dec 19, 2022
1 parent ef8dd6e commit 38c0d38
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function ButtonWithDialog<T extends HTMLElement = HTMLElement>({
}: ButtonWithDialogProps<T>) {
const [dialogOpen, setDialogOpen] = useState(false);

const Component = as || (attributes.className ? 'div' : Fragment);
const Component = as || (attributes.className ? 'button' : Fragment);

return (
<>
Expand Down
10 changes: 7 additions & 3 deletions packages/react/src/core/wallet/providers/sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,18 @@ export const SignInProvider = ({
}));
}, [setSignInState]);
const checkExpiration = useCallback(() => {
if (signInState?.siweMessage?.expirationTime) {
if (signInState.signedIn && signInState?.siweMessage?.expirationTime) {
const expirationTime = new Date(signInState.siweMessage.expirationTime);
const now = Date.now();
if (+expirationTime < +now) {
setSignInState((p) => ({ ...p, signedIn: false }));
signOut();
}
}
}, [signInState, setSignInState]);
}, [
signInState?.signedIn,
signInState?.siweMessage?.expirationTime,
signOut,
]);

useEffect(checkExpiration, [checkExpiration]);
useInterval(checkExpiration, 60_000);
Expand Down

0 comments on commit 38c0d38

Please sign in to comment.