|
|
@@ -46,7 +46,7 @@ router.post('/login', function (req, res) {
|
|
|
if (!user) {
|
|
|
return res.status(422).json({ message: 'user not found' });
|
|
|
}
|
|
|
-
|
|
|
+ console.log(user);
|
|
|
bcrypt.compare(password, user.password, function (err, result) {
|
|
|
if (result) {
|
|
|
res.json({ token: generateToken(user) });
|
|
|
@@ -80,14 +80,14 @@ router.post('/register', async function (req, res) {
|
|
|
if (existingUser) {
|
|
|
return res.status(403).json({ message: 'user already exists' });
|
|
|
}
|
|
|
-
|
|
|
// Hash the password
|
|
|
bcrypt.hash(password, saltRounds, async function (err, hash) {
|
|
|
if (err) {
|
|
|
return res.status(500).json({ error: err.message });
|
|
|
} else if (hash) {
|
|
|
// Insert user into database and generate token
|
|
|
- const user = await User.collection.insertOne({ email: email, password: hash });
|
|
|
+ await User.collection.insertOne({ email: email, password: hash });
|
|
|
+ const user = await User.findOne({ email: email });
|
|
|
return res.json({ token: generateToken(user) });
|
|
|
}
|
|
|
});
|