forked from bradtraversy/storybooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.js
28 lines (24 loc) · 679 Bytes
/
auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const express = require('express')
const passport = require('passport')
const router = express.Router()
// @desc Auth with Google
// @route GET /auth/google
router.get('/google', passport.authenticate('google', { scope: ['profile'] }))
// @desc Google auth callback
// @route GET /auth/google/callback
router.get(
'/google/callback',
passport.authenticate('google', { failureRedirect: '/' }),
(req, res) => {
res.redirect('/dashboard')
}
)
// @desc Logout user
// @route /auth/logout
router.get('/logout', (req, res, next) => {
req.logout((error) => {
if (error) {return next(error)}
res.redirect('/')
})
})
module.exports = router