fix(xo-server): make auth tokens created_at/expiration numbers
This commit is contained in:
@@ -14,6 +14,13 @@ const log = createLogger('xo:authentification')
|
||||
|
||||
const noSuchAuthenticationToken = id => noSuchObject(id, 'authenticationToken')
|
||||
|
||||
const unserialize = token => {
|
||||
if (token.created_at !== undefined) {
|
||||
token.created_at = +token.created_at
|
||||
}
|
||||
token.expiration = +token.expiration
|
||||
}
|
||||
|
||||
export default class {
|
||||
constructor(app) {
|
||||
app.config.watch('authentication', config => {
|
||||
@@ -209,6 +216,7 @@ export default class {
|
||||
}
|
||||
|
||||
token = token.properties
|
||||
unserialize(token)
|
||||
|
||||
if (!(token.expiration > Date.now())) {
|
||||
this._tokens.remove(id)::ignoreErrors()
|
||||
@@ -226,6 +234,8 @@ export default class {
|
||||
const tokensDb = this._tokens
|
||||
const toRemove = []
|
||||
for (const token of await tokensDb.get({ user_id: userId })) {
|
||||
unserialize(token)
|
||||
|
||||
const { expiration } = token
|
||||
if (expiration < now) {
|
||||
toRemove.push(token.id)
|
||||
|
||||
Reference in New Issue
Block a user