Skip to content

Instantly share code, notes, and snippets.

@funador
Created February 17, 2019 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funador/db1d288b31970e1eb7b88a76798ba80d to your computer and use it in GitHub Desktop.
Save funador/db1d288b31970e1eb7b88a76798ba80d to your computer and use it in GitHub Desktop.
const express = require('express')
const router = express.Router()
const passport = require('passport')
const authController = require('./auth.controller')
// Setting up the passport middleware for each of the OAuth providers
const twitterAuth = passport.authenticate('twitter')
const googleAuth = passport.authenticate('google', { scope: ['profile', 'email'] })
const facebookAuth = passport.authenticate('facebook')
const githubAuth = passport.authenticate('github')
const jwtAuth = passport.authenticate('jwt', {session: false})
// Routes that are triggered by the callbacks from each OAuth provider once
// the user has authenticated successfully
router.get('/twitter/callback', twitterAuth, authController.twitter)
router.get('/google/callback', googleAuth, authController.google)
router.get('/facebook/callback', facebookAuth, authController.facebook)
router.get('/github/callback', githubAuth, authController.github)
// Routes that are triggered on the client by the OAuth process
router.get('/twitter', twitterAuth)
router.get('/google', googleAuth)
router.get('/facebook', facebookAuth)
router.get('/github', githubAuth)
// Refresh and hydrate our user on page load
router.get('/refresh', jwtAuth, authController.refresh)
// Unlink a provider from the user account
router.delete('/unlink/:provider', jwtAuth, authController.unlink)
// Destroy the session when the user logs out
router.get('/logout', jwtAuth, authController.logout)
// Close the user's account
router.delete('/delete-account', jwtAuth, authController.deleteAccount)
module.exports = router
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment