mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-21 21:36:26 -08:00
fix generating token timers on startup
This commit is contained in:
parent
e01788de4f
commit
735878fe6a
|
@ -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))
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue