mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 19:59:20 +00:00
Start using sequelize migrations
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const { validationResult } = require("express-validator");
|
||||
const bcrypt = require("bcryptjs");
|
||||
const jwt = require("jsonwebtoken");
|
||||
const authConfig = require("../config/auth");
|
||||
|
||||
const User = require("../models/User");
|
||||
|
||||
@@ -9,17 +9,20 @@ exports.store = async (req, res, next) => {
|
||||
|
||||
const user = await User.findOne({ where: { email: email } });
|
||||
if (!user) {
|
||||
return res.status(400).json({ error: "No user found with this email" });
|
||||
return res.status(401).json({ error: "No user found with this email" });
|
||||
}
|
||||
|
||||
const isEqual = await bcrypt.compare(password, user.password);
|
||||
if (!isEqual) {
|
||||
if (!(await user.checkPassword(password))) {
|
||||
return res.status(401).json({ error: "Password does not match" });
|
||||
}
|
||||
|
||||
const token = jwt.sign({ email: user.email, userId: user.id }, "mysecret", {
|
||||
expiresIn: "24h",
|
||||
});
|
||||
const token = jwt.sign(
|
||||
{ email: user.email, userId: user.id },
|
||||
authConfig.secret,
|
||||
{
|
||||
expiresIn: authConfig.expiresIn,
|
||||
}
|
||||
);
|
||||
|
||||
return res
|
||||
.status(200)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const { validationResult } = require("express-validator");
|
||||
const bcrypt = require("bcryptjs");
|
||||
|
||||
const User = require("../models/User");
|
||||
|
||||
@@ -12,14 +11,7 @@ exports.store = async (req, res, next) => {
|
||||
.json({ error: "Validation failed", data: errors.array() });
|
||||
}
|
||||
|
||||
const { name, password, email } = req.body;
|
||||
|
||||
const hashedPw = await bcrypt.hash(password, 12);
|
||||
const user = User.build({
|
||||
email: email,
|
||||
password: hashedPw,
|
||||
name: name,
|
||||
});
|
||||
const result = await user.save();
|
||||
res.status(201).json({ message: "User created!", userId: result.id });
|
||||
const { name, id, email } = await User.create(req.body);
|
||||
// const result = await user.save();
|
||||
res.status(201).json({ message: "User created!", userId: id });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user