BinCode/services/auth.js
2025-01-17 15:05:21 -05:00

27 lines
603 B
JavaScript

const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken');
const { getDb } = require('../db/connect');
const { users: userQueries } = require('../db/queries');
const config = require('../config');
const hashPassword = async (password) => {
return bcrypt.hash(password, 10);
};
const verifyPassword = async (password, hash) => {
return bcrypt.compare(password, hash);
};
const generateToken = (userId) => {
return jwt.sign(
{ userId },
config.jwt.secret,
{ expiresIn: config.jwt.expiresIn }
);
};
module.exports = {
hashPassword,
verifyPassword,
generateToken
};