forked from KryptikApp/kryptikwebapp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauthWorker.ts
More file actions
30 lines (29 loc) · 806 Bytes
/
authWorker.ts
File metadata and controls
30 lines (29 loc) · 806 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
import { getActiveUser } from "./src/helpers/user";
import { KryptikFetch } from "./src/kryptikFetch";
async function handleRefreshTokens() {
console.log("refreshing auth tokens......");
try {
const res = await KryptikFetch("/api/auth/refresh", {
method: "POST",
timeout: 8000,
headers: { "Content-Type": "application/json" },
});
if (res.status != 200) {
throw new Error("Bad request");
}
} catch (e) {
// console.warn("Unable to refresh auth token. May need to log in again.");
}
}
handleRefreshTokens().then(() => {
postMessage(true);
});
// silent auth refresh
// runs every twelve minutes
setInterval(() => {
handleRefreshTokens().then(() => {
getActiveUser().then((u) => {
console.log("User refreshed!");
});
});
}, 32400000);