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)) })