Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React 2019 Course | Bcrypt error #21

Open
JonattanD1440 opened this issue Dec 25, 2019 · 12 comments
Open

React 2019 Course | Bcrypt error #21

JonattanD1440 opened this issue Dec 25, 2019 · 12 comments

Comments

@JonattanD1440
Copy link

JonattanD1440 commented Dec 25, 2019

Unable to run "npm i", because i'm getting a bcrypt error unable to download and some other dependencies like node, node-gyp and node-pre-gy.
My solution was to installing these packages on their own and instead of using bcrypt, i used bcryptjs.
Afterwards you need to go into the auth and users file and change:
const bcrypt = require("bcrypt");
to
const bcrypt = require("bcryptjs");
and it should be working fine.

@JonattanD1440 JonattanD1440 changed the title React 2019 Course React 2019 Course | Bcrypt error Dec 25, 2019
@mamoyz
Copy link

mamoyz commented Jan 4, 2020

Unable to run "npm i", because i'm getting a bcrypt error unable to download and some other dependencies like node, node-gyp and node-pre-gy.
My solution was to installing these packages on their own and instead of using bcrypt, i used bcryptjs.
Afterwards you need to go into the auth and users file and change:
const bcrypt = require("bcrypt");
to
const bcrypt = require("bcryptjs");
and it should be working fine.

Open file "package.json" and remove "bcrypt"

Then Install bcrypt-nodejs using:
npm install --save bcrypt-nodejs && npm uninstall --save bcrypt

Replace "bcrypt" with "bcrypt-nodejs" in these files:

\vidly-api-node\routes\users.js
\vidly-api-node\routes\auth.js

@pouriamoosavi
Copy link

I faced the same error but instead of changing files, I just installed bcrypt@latest and it is working just fine. Hope it helps

@jalexandremoreira
Copy link

Even after trying some of the above proposed solutions and also following some advice from a friend, I still have no success. I'm still left with: "3 vulnerabilities (2 moderate, 1 high)"

@ybakhshi
Copy link

ybakhshi commented Feb 1, 2020

@mamoyz very helpful bro! God bless you man!

@factorlive
Copy link

Do follow @pouriamoosavi advice and install the latest bcrypt.
npm i bcrypt@latest
No need to edit package.json for me.
Running MacOs 10.14.6 and using the git repo as opposed to the zip file on Mosh page behind the paywall.

@ybakhshi
Copy link

ybakhshi commented Feb 2, 2020

@factorlive i updated the bcrypt to latest but on windows 10 it didn't work out . but solution from @mamoyz worked out. I have now another issue with users . i get a 500 internal server error while submitting the registration form! any solution?

@Ozball
Copy link

Ozball commented Mar 20, 2020

I have now another issue with users . i get a 500 internal server error while submitting the registration form! any solution?

@ybakhshi if you're still having issues with this, I believe I've found a solution. If using bcrypt-nodejs as @mamoyz suggests then the following two lines need adjusting in users.js

Line 21:
const salt = await bcrypt.genSalt(10);
changes to
const salt = await bcrypt.genSaltSync(10);

and
Line 22:
user.password = await bcrypt.hash(user.password, salt);
changes to
user.password = await bcrypt.hashSync(user.password, salt);

This seemed to get around the issue for me.

Also if you then run into issues during the login form section replace
auth.js:Line 16
const validPassword = await bcrypt.compare(req.body.password, user.password);
with
const validPassword = await bcrypt.compareSync(req.body.password, user.password);

@abdulloooh
Copy link

Unable to run "npm i", because i'm getting a bcrypt error unable to download and some other dependencies like node, node-gyp and node-pre-gy.
My solution was to installing these packages on their own and instead of using bcrypt, i used bcryptjs.
Afterwards you need to go into the auth and users file and change:
const bcrypt = require("bcrypt");
to
const bcrypt = require("bcryptjs");
and it should be working fine.

Open file "package.json" and remove "bcrypt"

Then Install bcrypt-nodejs using:
npm install --save bcrypt-nodejs && npm uninstall --save bcrypt

Replace "bcrypt" with "bcrypt-nodejs" in these files:

\vidly-api-node\routes\users.js
\vidly-api-node\routes\auth.js

If you are installing bcryptjs in 2020, you are going to change require("bcrypt") to require("bcrypt-nodejs") and not require("bcryptjs")

@averyfreeman
Copy link

Even after trying some of the above proposed solutions and also following some advice from a friend, I still have no success. I'm still left with: "3 vulnerabilities (2 moderate, 1 high)"

If you tried installing bcrypt already and are planning to change to bcryptjs, try removing bcrypt first (had similar error, and it worked for me)

@qlian100
Copy link

if you get the error"bcrypt-nodejs is no longer actively maintained. Please use bcrypt or bcryptjs. "

This is what I did

Open file "package.json" and remove "bcrypt"

Then Install bcrypt-nodejs using:
npm i bcrypt

@mrluisrodriguez19
Copy link

I have now another issue with users . i get a 500 internal server error while submitting the registration form! any solution?

@ybakhshi if you're still having issues with this, I believe I've found a solution. If using bcrypt-nodejs as @mamoyz suggests then the following two lines need adjusting in users.js

Line 21:
const salt = await bcrypt.genSalt(10);
changes to
const salt = await bcrypt.genSaltSync(10);

and
Line 22:
user.password = await bcrypt.hash(user.password, salt);
changes to
user.password = await bcrypt.hashSync(user.password, salt);

This seemed to get around the issue for me.

Also if you then run into issues during the login form section replace
auth.js:Line 16
const validPassword = await bcrypt.compare(req.body.password, user.password);
with
const validPassword = await bcrypt.compareSync(req.body.password, user.password);

This did it for me. Thanks!

@amir2mi
Copy link

amir2mi commented Sep 27, 2021

It gave me 404 error and I changed the Bcrypt version in package.json to the last version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests