optimizes refreshCookie

This commit is contained in:
James
2020-07-13 18:10:27 -04:00
parent 5b5375ee32
commit 7c99e4cda0
2 changed files with 6 additions and 3 deletions

View File

@@ -39,7 +39,10 @@ const UserProvider = ({ children }) => {
const email = user?.email;
const refreshCookie = useCallback(() => {
if (email) {
const now = Math.round((new Date()).getTime() / 1000);
const remainingTime = (exp || 0) - now;
if (exp && remainingTime < 120) {
setTimeout(async () => {
const request = await requests.post(`${serverURL}${api}/${userSlug}/refresh-token`);
@@ -51,7 +54,7 @@ const UserProvider = ({ children }) => {
}
}, 1000);
}
}, [setUser, history, email]);
}, [setUser, history, exp]);
const setToken = useCallback((token) => {
const decoded = jwt.decode(token);

View File

@@ -6,7 +6,7 @@
.relationship__error-loading {
border: 1px solid $color-red;
height: base(2);
min-height: base(2);
padding: base(.5) base(.75);
background-color: $color-red;
color: white;