fix: false positive auth true by existing expired jwt
This commit is contained in:
parent
a20c0d3ed3
commit
e607f8c599
1 changed files with 4 additions and 0 deletions
|
@ -55,6 +55,7 @@ export async function isAuthenticatedPromise(forceRefresh: boolean = false): Pro
|
||||||
// check jwt expiry
|
// check jwt expiry
|
||||||
const exp = decoded.exp ?? 0;
|
const exp = decoded.exp ?? 0;
|
||||||
const correctedLocalTime = new Date().getTime();
|
const correctedLocalTime = new Date().getTime();
|
||||||
|
let failedRefresh = false;
|
||||||
if (exp < Math.floor(correctedLocalTime / 1000) || forceRefresh) {
|
if (exp < Math.floor(correctedLocalTime / 1000) || forceRefresh) {
|
||||||
await refreshToken()
|
await refreshToken()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
@ -63,10 +64,13 @@ export async function isAuthenticatedPromise(forceRefresh: boolean = false): Pro
|
||||||
.catch((err: string) => {
|
.catch((err: string) => {
|
||||||
console.log("expired");
|
console.log("expired");
|
||||||
auth.setFailed();
|
auth.setFailed();
|
||||||
|
failedRefresh = true;
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (failedRefresh) return;
|
||||||
|
|
||||||
var { userId, firstname, lastname, mail, username, permissions, isOwner } = decoded;
|
var { userId, firstname, lastname, mail, username, permissions, isOwner } = decoded;
|
||||||
|
|
||||||
if (Object.keys(permissions ?? {}).length === 0 && !isOwner) {
|
if (Object.keys(permissions ?? {}).length === 0 && !isOwner) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue