27 lines
603 B
JavaScript
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
|
|
}; |