Utilities for chaining multiple Passport authentication middlewares
You have multiple Passport authentication strategies, and you need all of them to run before considering the user to be authenticated.
For instance, you may wish to authenticate with username and password (via passport-local), then also pass an OTP or CAPTCHA check in a separate strategy.
- Node.js 8+
- Passport strategies of your choice
$ npm install --save passport-compose
const passportCompose = ;const compose loginRedirect isAuthenticated =;// This example assumes you have set up an express application called "app",// and have required and configured "local" and "otp" strategies for passport// Do not set "successRedirect" or "successReturnToOrRedirect" here, or a// passing strategy will redirect before the next one runsconst localSettings = failureRedirect: "/login" ;const otpSettings = failureRedirect: "/login" ;// Require successful username+password and OTP authentication, then redirectconst strategies =passport)passport);app;// To require all strategies to pass before accessing a resource:app;