-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathverify.js
More file actions
32 lines (25 loc) · 793 Bytes
/
verify.js
File metadata and controls
32 lines (25 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const verify = () => {
const expiresIn = localStorage.getItem('expiresIn');
let timer;
if (expiresIn == null || expiresIn == undefined) {
localStorage.removeItem('expiresIn');
localStorage.removeItem('token');
return false;
}
const remainingTime = parseInt(expiresIn) - new Date().getTime();
timer = setTimeout(() => {
if (remainingTime <= 1000) {
localStorage.removeItem('expiresIn');
localStorage.removeItem('token');
return false;
}
}, remainingTime - 1000);
if (remainingTime <= 0) {
localStorage.removeItem('expiresIn');
localStorage.removeItem('token');
clearTimeout(timer);
return false;
}
return true;
};
module.exports = verify;