fix generating token timers on startup

This commit is contained in:
May 2024-06-18 11:11:06 -07:00
parent e01788de4f
commit 735878fe6a

View file

@ -17,9 +17,9 @@ export type TokenResolvable = string | AuthToken
export const Db = new DbFile<AuthToken[]>("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))
})