Skip to content

Passport.js

Many applications offer multiple ways to login beyond just the classic username + password. For example, you may want your users to login with their google or facebook account. No problem! StarterStack comes bundled with Passport.js which provides 500+ strategies for login. We got you started with including the passport-local strategy. In fact, this is enabled by default.

Adding Another Strategy

First, we strongly encourage you to read the Passport.js docs. Once you have selected the strategy to implement, including importing the npm package there are a few things to understand about how we've incorparated Passport.js.

Register Your Strategy

Passport.js talks about registering your strategy before you can use it. StarterStack provides a file located at /backend/middleware/passport/Strategies.js. You will find the passport-local strategy there. Following that example by importing your npm strategy and implementing the strategy according the docs.

Implement Your Strategy Callback

When you strategy successfully authenticates, it will want to execute a callback to handle post authentication logic. Again, follow the Passport.js specific strategy documentation for implementation details. Place this callback in /backend/middleware/passport/StrategyCallbacks.js

Configure StarterStack to Use Your Strategy

Finally, in your .env file, set the PASSPORT_STRATEGY var to the name of your strategy. Leave off the passport- prefix. For example, passport-facebook becomes facebook