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

Cannot read properties of undefined (reading 'hashSync') [BUG] #10

Closed
lollobene opened this issue Dec 16, 2022 · 3 comments · Fixed by #12
Closed

Cannot read properties of undefined (reading 'hashSync') [BUG] #10

lollobene opened this issue Dec 16, 2022 · 3 comments · Fixed by #12
Assignees
Labels
bug Something isn't working

Comments

@lollobene
Copy link
Contributor

Describe the bug
The bug happens when trying to create a new user through the /auth/register/ endpoint.

The error is in /src/auth/auth.service.ts:73:33
userDTO.password = bcryptjs.hashSync(body.password, 10);

Seems that bcryptjs is undefined

To Reproduce
Steps to reproduce the behaviour:

  1. install PostgreSQL docker container and configure it
  2. run ./setup.sh
  3. run 'npm run start'
  4. trigger http request using insomnia (or postman)
  5. See an error on the server console

Expected behaviour
The request should create a new user in the database

Screenshots
image

Environment (please complete the following information):

  • OS: macOS Ventura 13.1 (22C65)
  • Node: v16.18.1
  • npm: 8.19.2

Additional context
none

@lollobene lollobene added the bug Something isn't working label Dec 16, 2022
@lollobene
Copy link
Contributor Author

I found a solution for that, just change some lines of code inside src/auth/auth.service.ts:

line 3:
import bcryptjs from 'bcryptjs'; becomes import { compareSync, hashSync } from 'bcryptjs';

line 46:
bcryptjs.compareSync(...); becomes compareSync(...);

line 73:
bcryptjs.hashSync(...) becomes hashSync(...)

@josephgoksu
Copy link
Owner

Thank you for bringing this up, @lollobene. It appears that the latest version of the library has differences in how their modules are exported.

If you resolve the issue on your side, a PR is highly appreciated. Thank you :)

@lollobene
Copy link
Contributor Author

lollobene commented Dec 17, 2022

Yeah I just opened a PR :) @joeygoksu
Thank you!

@josephgoksu josephgoksu linked a pull request Dec 20, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants