mikenicholson / passport-jwt

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

Unable to use passport strategy twice #150

Closed tobieeniafe closed 5 years ago

tobieeniafe commented 6 years ago

I'm trying to authenticate both users and admin using passport-jwt. I created two passport strategies, but for some reason, i get unauthorized on whichever strategy I add first to my file while the second one works. I tried separating them into files still no solution. is there a way around this? screenshot 223 screenshot 221 screenshot 222

mikenicholson commented 5 years ago

See the implementation of passport.use(). You need to give each strategy a new name, otherwise, the default name ('jwt') is used and the last strategy passed to passport.use() overwrites the previous one.

You should be able to do something like:

// for cleaner
passport.use('jwt-cleaner', new JwtStrategy(....));
...
// for customer
passport.use('jwt-customer', new JwtStrategy(...));
mikenicholson commented 5 years ago

Closing. Feel free to re-opn if you can demonstrate an issue with this strategy.