Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const router = express.Router()
- passport.use(new BearerStrategy(
- { passReqToCallback: true },
- async function (req, token, done) {
- if (token) {
- // business logic
- }
- }));
- router.post("/",
- passport.authenticate('bearer', { session: false, passReqToCallback: true, failWithError: true },
- function (req, res, next) { // handle success
- },
- function (err, req, res, next) { // handle failure
- });
- router.get("/",
- passport.authenticate('bearer', { session: false, passReqToCallback: true, failWithError: true },
- function (req, res, next) { // handle success
- },
- function (err, req, res, next) { // handle failure
- });
- router.get("/:username",
- passport.authenticate('bearer', { session: false, passReqToCallback: true, failWithError: true },
- function (req, res, next) { // handle success
- },
- function (err, req, res, next) { // handle failure
- });
- passport.use('local-login', new LocalStrategy({ ... })
- passport.use('local-signup', new LocalStrategy({ ... })
- router.post('/signup', passport.authenticate('local-signup', {
- successRedirect : '/auth/profile',
- failureRedirect : 'auth/signup'
- }));
- router.post('/login', passport.authenticate('local-login', {
- successRedirect : '/auth/profile',
- failureRedirect : 'auth/login'
- }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement