Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export const store = function(req, res) {
- const { email, password, passwordRepeat } = req.body;
- const currentDate = new Date();
- if (password !== passwordRepeat) {
- console.log('passwords dont match');
- return;
- }
- hash(password).then((hash) => {
- const user = {
- email,
- password: hash,
- created_at: currentDate,
- updated_at: currentDate
- };
- query('insert into users set ?', user, (err, result) => {
- if (err) {
- throw err;
- }
- console.log('success', result);
- });
- }).catch((err) => {
- console.log(err);
- });
- };
- export const hash = (str) => {
- const saltRounds = 10;
- return new Promise((resolve, reject) => {
- bcrypt.hash(str, saltRounds, (err, hash) => {
- if (err) {
- reject(err);
- } else {
- resolve(hash);
- }
- });
- });
- };
Add Comment
Please, Sign In to add comment