Skip to content

Commit e2e980c

Browse files
author
Mohammed Othman
authored
Merge pull request #29 from mohammedothman7/db-connect-fix
Db connect fix
2 parents c5195db + b2c06be commit e2e980c

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"dependencies": {
1111
"axios": "^0.19.2",
12-
"bcrypt": "^5.0.0",
12+
"bcryptjs": "^2.4.3",
1313
"body-parser": "^1.19.0",
1414
"compression": "^1.7.4",
1515
"cookie-parser": "~1.4.4",

routes/users.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var express = require("express");
2-
const bcrypt = require('bcrypt')
2+
const bcrypt = require("bcryptjs");
33
var router = express.Router();
44
const { User } = require("../database/models");
55

@@ -28,15 +28,19 @@ router.get("/:username/:password", async (req, res, next) => {
2828
username: req.params.username,
2929
},
3030
});
31-
31+
3232
// Verifying password matches hashed
33-
bcrypt.compare(req.params.password, user.password, function(err, response) {
34-
if(response){
35-
res.status(200).json(user);
36-
} else {
37-
res.status(401).json();
33+
bcrypt.compare(
34+
req.params.password,
35+
user.password,
36+
function (err, response) {
37+
if (response) {
38+
res.status(200).json(user);
39+
} else {
40+
res.status(401).json();
41+
}
3842
}
39-
})
43+
);
4044
} catch (err) {
4145
next(err);
4246
}
@@ -49,7 +53,7 @@ router.post("/", async (req, res, next) => {
4953
const { firstName, lastName, email, username, password } = req.body;
5054

5155
// Hashing password
52-
bcrypt.hash(password, 10, async function(err, hash) {
56+
bcrypt.hash(password, 10, async function (err, hash) {
5357
if (err) next(err);
5458

5559
// Create a user object
@@ -60,7 +64,7 @@ router.post("/", async (req, res, next) => {
6064
username: username,
6165
password: hash,
6266
};
63-
67+
6468
try {
6569
// Create a new user on the database
6670
const newUser = await User.create(userObj);

0 commit comments

Comments
 (0)