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

Problems in node 9 and crypto #9

Closed
LordSuricato opened this issue Dec 19, 2017 · 3 comments
Closed

Problems in node 9 and crypto #9

LordSuricato opened this issue Dec 19, 2017 · 3 comments

Comments

@LordSuricato
Copy link

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function at randomBytes (internal/crypto/random.js:44:11)
It is explained here
https://github.com/diegohaz/rest/issues/133

@sehrope
Copy link
Owner

sehrope commented Dec 19, 2017

This is due a breaking change (for undocumented behavior) in NodeJS v9. See here for more details on the cause: nodejs/node#16778

This is fixed in newer version of rand-token by commit 763df11. Upgrade to the latest version (v0.4.0 as of writing this) of rand-token and it'll be resolved.

@sehrope sehrope closed this as completed Dec 19, 2017
@martinbedouret
Copy link

I have updated to v0.4.0 and the same issue still there. I'm on ubuntu 17 node 9.3

@sehrope
Copy link
Owner

sehrope commented Jan 3, 2018

@martinbedouret Clear your dependencies (via rm -rf node_modules) and try again. You probably have the older version cached in node_modules. If that doesn't fix it then submit a separate issue with steps to reproduce.

$ node --version
v9.3.0

$ npm install rand-token
+ rand-token@0.4.0
added 1 package in 0.58s

$ node -p "require('rand-token').uid(16)"
Fy28UXPDr2vnL0Wz

pincheira added a commit to pincheira/react-native-authentication that referenced this issue Mar 1, 2018
The app is crashing when calling the `login` action on `UsersAuthController`, due to an undocumented change in Node.js v9 that breaks `rand-token`, but it was fixed on version `0.4.0`. I am using Node.js `9.5.0` and I can confirm crash is now gone after this update.

Error output was:
```
internal/crypto/random.js:44
    throw new errors.TypeError('ERR_INVALID_CALLBACK');
    ^

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
    at Object.randomBytes (internal/crypto/random.js:44:11)
    at Object.options.source (/Users/jp/spare/react-native-authentication/server/node_modules/rand-token/index.js:60:25)
    at Object.generate (/Users/jp/spare/react-native-authentication/server/node_modules/rand-token/index.js:95:29)
    at child.findOrAdd (/Users/jp/spare/react-native-authentication/server/api/models/Tokens.js:31:21)
    at child.wrapper [as findOrAdd] (/Users/jp/spare/react-native-authentication/server/node_modules/lodash/index.js:3095:19)
    at passport.authenticate (/Users/jp/spare/react-native-authentication/server/api/controllers/UsersAuthController.js:36:18)
    at BasicStrategy.strategy.success (/Users/jp/spare/react-native-authentication/server/node_modules/passport/lib/middleware/authenticate.js:201:18)
    at verified (/Users/jp/spare/react-native-authentication/server/node_modules/passport-http/lib/passport-http/strategies/basic.js:91:10)
    at bcrypt.compare (/Users/jp/spare/react-native-authentication/server/config/passport.js:48:13)
```

More info: sehrope/node-rand-token#9

Cheers and thank you for your post! https://medium.com/@alexmngn/the-essential-boilerplate-to-authenticate-users-on-your-react-native-app-f7a8e0e04a42 👍🏻 🍻
sdelafond added a commit to sdelafond/deploiement.consultation that referenced this issue May 11, 2020
See for instance:

  - whitef0x0/node-email-verification#78
  - sehrope/node-rand-token#9

Ideally we'd bump up the dependency on rand-token to 0.4.0, and release
a new consultation-verification package. However, we can't publish
consultation-verification to npmjs.com, because we do not have the
required credentials. Until
consultation-gouv/npm.verif.consultation#3 is
fixed, this nasty manual fix will have to do.
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

3 participants