Full stack serverless template

This commit is contained in:
2021-09-22 09:23:42 -05:00
parent 3a410213b9
commit ae37645212
45 changed files with 2373 additions and 16 deletions

35
api/utils/index.js Normal file
View File

@@ -0,0 +1,35 @@
/**
* Utils
*/
const bcrypt = require('bcryptjs')
/**
* Validate email address
*/
const validateEmailAddress = (email) => {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
return re.test(String(email).toLowerCase())
}
/**
* Hash password
* @param {*} user
*/
const hashPassword = (password) => {
const salt = bcrypt.genSaltSync(10)
return bcrypt.hashSync(password, salt)
}
/**
* Compare password
*/
const comparePassword = (candidatePassword, trustedPassword) => {
return bcrypt.compareSync(candidatePassword, trustedPassword)
}
module.exports = {
hashPassword,
comparePassword,
validateEmailAddress
}