bradtraversy / meanauthapp

Complete MEAN stack app with authentication
242 stars 152 forks source link

Error occurred when posting username and password by postman #19

Closed 0xrolin closed 7 years ago

0xrolin commented 7 years ago

I followed meanauthapp video tutorial part 4 and I'm struggling with a bug. The error occurred when I post username and password by postman to url "http://localhost:3000/users/authenticate". The terminal result:

`/Volumes/Work/Learning/MEAN stack/meanauthapp/node_modules/jsonwebtoken/sign.js:89 throw err; ^

Error: Expected object at validate (/Volumes/Work/Learning/MEAN stack/meanauthapp/node_modules/jsonwebtoken/sign.js:34:11) at Object.module.exports [as sign] (/Volumes/Work/Learning/MEAN stack/meanauthapp/node_modules/jsonwebtoken/sign.js:100:7) at User.comparePassword (/Volumes/Work/Learning/MEAN stack/meanauthapp/routes/users.js:40:23) at bcrypt.compare (/Volumes/Work/Learning/MEAN stack/meanauthapp/models/user.js:48:3) at /Volumes/Work/Learning/MEAN stack/meanauthapp/node_modules/bcryptjs/dist/bcrypt.js:297:21 at /Volumes/Work/Learning/MEAN stack/meanauthapp/node_modules/bcryptjs/dist/bcrypt.js:1353:21 at Immediate.next [as _onImmediate] (/Volumes/Work/Learning/MEAN stack/meanauthapp/node_modules/bcryptjs/dist/bcrypt.js:1233:21) at runCallback (timers.js:781:20) at tryOnImmediate (timers.js:743:5) at processImmediate [as _immediateCallback] (timers.js:714:5)`

I think the occurring error part is : const token = jwt.sign(user, config.secret, { expiresInMinutes : 604800 // 1 week }); The sign function. Is it version problem?

0xrolin commented 7 years ago

I found the solution. I changed expiresInMinutes to expiresIn. Maybe version problem.