backend/src/utils/auth.utils.js

24 lines
630 B
JavaScript
Raw Normal View History

const log = require('../utils/log.utils');
const crypto = require('crypto')
const db = require('../services/dbAccess.services')
// Checks users registration key against issued keys
async function checkUser(key) {
q = {uuid: key};
res = db.query(q);
log.out(`authUtils.checkUser: DB Query answer: ${await res}`)
return await res
}
// Creates an API key for a user
async function generateKey() {
const saltRounds = 10
const token = crypto.randomUUID()
const hash = bcrypt.hash(token, saltRounds);
return {user_key: token, hash_key: await hash}
};
module.export = {
checkUser,
generateKey
}