Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. const router = express.Router()
  2.  
  3. passport.use(new BearerStrategy(
  4. { passReqToCallback: true },
  5. async function (req, token, done) {
  6. if (token) {
  7. // business logic
  8. }
  9. }));
  10.  
  11. router.post("/",
  12. passport.authenticate('bearer', { session: false, passReqToCallback: true, failWithError: true },
  13. function (req, res, next) { // handle success
  14. },
  15. function (err, req, res, next) { // handle failure
  16. });
  17.  
  18. router.get("/",
  19. passport.authenticate('bearer', { session: false, passReqToCallback: true, failWithError: true },
  20. function (req, res, next) { // handle success
  21. },
  22. function (err, req, res, next) { // handle failure
  23. });
  24.  
  25. router.get("/:username",
  26. passport.authenticate('bearer', { session: false, passReqToCallback: true, failWithError: true },
  27. function (req, res, next) { // handle success
  28. },
  29. function (err, req, res, next) { // handle failure
  30. });
  31.  
  32. passport.use('local-login', new LocalStrategy({ ... })
  33. passport.use('local-signup', new LocalStrategy({ ... })
  34.  
  35. router.post('/signup', passport.authenticate('local-signup', {
  36. successRedirect : '/auth/profile',
  37. failureRedirect : 'auth/signup'
  38. }));
  39.  
  40. router.post('/login', passport.authenticate('local-login', {
  41. successRedirect : '/auth/profile',
  42. failureRedirect : 'auth/login'
  43. }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement