fix: added variables to the constants file.

fix: updated sql queries with constants
This commit is contained in:
Sérgio Salgado 2021-04-27 00:22:54 +01:00 committed by Josh Harvey
parent 3c2cbac23f
commit aa7252dfce
5 changed files with 35 additions and 16 deletions

14
lib/auth-tokens.js Normal file
View file

@ -0,0 +1,14 @@
const crypto = require('crypto')
const constants = require('./constants')
function createAuthToken (userID, type) {
const token = crypto.randomBytes(32).toString('hex')
const sql = `INSERT INTO auth_tokens (token, type, user_id) VALUES ($1, $2, $3) ON CONFLICT (user_id, type) DO UPDATE SET token=$1, expire=now() + interval '${constants.AUTH_TOKEN_EXPIRATION_TIME}' RETURNING *`
return db.one(sql, [token, type, userID])
}
module.exports = {
createAuthToken
}