mirror of
https://github.com/wukko/cobalt.git
synced 2025-01-23 11:16:20 +01:00
api/jwt: return relative expiration date to accommodate offset clocks
This commit is contained in:
parent
1f3509db07
commit
c698d272a1
2 changed files with 4 additions and 3 deletions
|
@ -28,7 +28,7 @@ export const generate = () => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
token: `${header}.${payload}.${signature}`,
|
token: `${header}.${payload}.${signature}`,
|
||||||
exp,
|
exp: env.jwtLifetime - 2,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,10 +42,10 @@ export const requestSession = async() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getSession = async () => {
|
export const getSession = async () => {
|
||||||
const currentTime = Math.floor(new Date().getTime() / 1000);
|
const currentTime = () => Math.floor(new Date().getTime() / 1000);
|
||||||
const cache = get(cachedSession);
|
const cache = get(cachedSession);
|
||||||
|
|
||||||
if (cache?.token && cache?.exp - 2 > currentTime) {
|
if (cache?.token && cache?.exp - 2 > currentTime()) {
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ export const getSession = async () => {
|
||||||
} as CobaltErrorResponse
|
} as CobaltErrorResponse
|
||||||
|
|
||||||
if (!("status" in newSession)) {
|
if (!("status" in newSession)) {
|
||||||
|
newSession.exp = currentTime() + newSession.exp;
|
||||||
cachedSession.set(newSession);
|
cachedSession.set(newSession);
|
||||||
}
|
}
|
||||||
return newSession;
|
return newSession;
|
||||||
|
|
Loading…
Reference in a new issue