From bc72d2cbf608864adb22e63ee07315fffb3ff49d Mon Sep 17 00:00:00 2001 From: James Date: Tue, 31 Mar 2020 20:18:57 -0400 Subject: [PATCH] uses remaining token time to calculate when to show stay logged in modal --- src/client/components/data/User.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/client/components/data/User.js b/src/client/components/data/User.js index 5418024572..2f3e766d07 100644 --- a/src/client/components/data/User.js +++ b/src/client/components/data/User.js @@ -65,23 +65,23 @@ const UserProvider = ({ children }) => { }, [token]); useEffect(() => { - const { tokenExpiration } = config.user.auth; - let reminder = false; let forceLogOut = false; - console.log(user?.exp); + const exp = user?.exp || 0; + const now = Math.round((new Date()).getTime() / 1000); + const remainingTime = exp - now; - if (user && isNotExpired(user)) { + if (remainingTime > 0) { reminder = setTimeout(() => { toggleModal('stay-logged-in'); - }, (tokenExpiration - 60) * 1000); + }, (remainingTime - 60)); forceLogOut = setTimeout(() => { const { routes: { admin } } = config; history.push(`${admin}/logout`); closeAllModals(); - }, tokenExpiration * 1000); + }, remainingTime); } return () => {