madhums / node-express-mongoose-demo

A simple demo app using node and mongodb for beginners (with docker)
https://nodejs-express-demo.fly.dev
MIT License
5.12k stars 1.38k forks source link

req.user problem #362

Closed the-einstein closed 3 years ago

the-einstein commented 4 years ago

I wanted to add types to user as admin or just user. but I am not realizing where you gave these params

{
 name: 'name ',
  username: 'username ',
  _id: id
}

i want to add new param here as role, but anytime I change the page the req.user params are also hanged and got got only these three params. I want to have { name: 'name', username: 'username', role: "role", _id: id }

jojomak13 commented 4 years ago

you need to edit user schema from user model and add role in its's schema and give it a default value as user

the-einstein commented 4 years ago

you need to edit user schema from user model and add role in its's schema and give it a default value as user

I am sorry but this won't help in my condition

madhums commented 3 years ago

It depends what you deserialise and pass to the req.user in session.

This is where you change it. https://github.com/madhums/node-express-mongoose-demo/blob/master/config/passport.js#L23

Check out https://stackoverflow.com/questions/27637609/understanding-passport-serialize-deserialize