mirror of
https://github.com/wukko/cobalt.git
synced 2025-06-13 13:47:38 +02:00
api/jwt: return relative expiration date to accommodate offset clocks
This commit is contained in:
@ -28,7 +28,7 @@ export const generate = () => {
|
||||
|
||||
return {
|
||||
token: `${header}.${payload}.${signature}`,
|
||||
exp,
|
||||
exp: env.jwtLifetime - 2,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -42,10 +42,10 @@ export const requestSession = 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);
|
||||
|
||||
if (cache?.token && cache?.exp - 2 > currentTime) {
|
||||
if (cache?.token && cache?.exp - 2 > currentTime()) {
|
||||
return cache;
|
||||
}
|
||||
|
||||
@ -59,6 +59,7 @@ export const getSession = async () => {
|
||||
} as CobaltErrorResponse
|
||||
|
||||
if (!("status" in newSession)) {
|
||||
newSession.exp = currentTime() + newSession.exp;
|
||||
cachedSession.set(newSession);
|
||||
}
|
||||
return newSession;
|
||||
|
Reference in New Issue
Block a user