jaredhanson / passport-local

Username and password authentication strategy for Passport and Node.js.
https://www.passportjs.org/packages/passport-local/?utm_source=github&utm_medium=referral&utm_campaign=passport-local&utm_content=about
MIT License
2.74k stars 498 forks source link

How to use local strategy on multiple Models? #170

Closed harishankards closed 6 years ago

harishankards commented 6 years ago

Hi,

In my project, I'm having different models say Contractor, Purchaser and Seller. I want to authenticate them. How to configure the passport js for local strategy.

If possible, please let me know the facebook and linkedin auth also.

xiangZgnaix commented 6 years ago

Hey Dude! I've met the same problem recently! To solve it, you can just instantiate two local strategies. Something different is that you need to change the name of the instantiated strategy before you add it to the passport use middleware. Meanwhile, when you use the strategy with passport.authenticate function, the name you input is no longer the default 'local' but the name you set above!!!

harishankards commented 6 years ago

Hey @xiangZgnaix ,

Thanks for the help. I fixed it myself in the same way mentioned above long back. Thank you!

usamamashkoor commented 4 years ago

Hi @xiangZgnaix and @harishankards I have implemented two local strategies but in my case even if an admin authenticates, it gets written to req.user and when a user authenticates, it gets written to req.user.I want to get req.user and req.admin, but every time it gets written to req.user,

Can any of you help me with this, please?

Thanks