From 735878fe6ad0c006f071c0485a2d4313e0c80a0a Mon Sep 17 00:00:00 2001 From: stringsplit <77242831+nbitzz@users.noreply.github.com> Date: Tue, 18 Jun 2024 11:11:06 -0700 Subject: [PATCH] fix generating token timers on startup --- src/server/lib/auth.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/server/lib/auth.ts b/src/server/lib/auth.ts index eb62d61..f0e133a 100644 --- a/src/server/lib/auth.ts +++ b/src/server/lib/auth.ts @@ -17,9 +17,9 @@ export type TokenResolvable = string | AuthToken export const Db = new DbFile("tokens", []) -export function resolve(token: TokenResolvable) { +export function resolve(token: TokenResolvable, forCleanup?: boolean) { let resolved = typeof token == "object" ? token : Db.data.find(e => e.id == token) - if (resolved && (resolved.expire == null || Date.now() < resolved.expire)) + if (resolved && (forCleanup || resolved.expire == null || Date.now() < resolved.expire)) return resolved } @@ -105,7 +105,7 @@ export function tokenTimer(token: AuthToken) { } export function invalidate(_token: TokenResolvable) { - let token = resolve(_token)! + let token = resolve(_token, true)! if (AuthTokenTO[token.id]) { clearTimeout(AuthTokenTO[token.id]) } @@ -118,6 +118,6 @@ export function invalidate(_token: TokenResolvable) { } Db.read() - .then((buf) => { + .then(() => { Db.data.forEach((e) => tokenTimer(e)) })