mikenicholson / passport-jwt

Passport authentication using JSON Web Tokens
MIT License
1.96k stars 213 forks source link

Multiple passport-jwt strategy in the same app #182

Closed kssoftware93 closed 4 years ago

kssoftware93 commented 5 years ago

How can I created two different passport-jwt using different passwords and use it to authenticate two different roles? i test this https://stackoverflow.com/questions/39795898/multiple-passport-jwt-strategy-in-the-same-app?answertab=votes#tab-top work for me

niksauer commented 4 years ago

This is easy, simply name each strategy as following:

passport.use("strategyA", new JwtStrategy(jwtOptions, (payload, done) => {  ... });
passport.use("strategyB", new JwtStrategy(jwtOptions, (payload, done) => {  ... });

and use them analogously:

rootRouter.use(passport.authenticate("strategyA", { session: false }));