-
Notifications
You must be signed in to change notification settings - Fork 1
/
router.js
43 lines (34 loc) · 1.08 KB
/
router.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const passport = require('passport');
module.exports = (express) => {
const router = express.Router();
function isLoggedIn(req, res, next) {
if (req.isAuthenticated()) {
return next();
}
res.redirect('/login');
}
router.get('/login', (req, res) => {
res.render("login", {
});
});
router.post('/login', passport.authenticate('local-login', {
successRedirect: '/profile',
failureRedirect: '/error'
}));
router.get('/error', (req, res) => {
res.send('You are not logged in!');
});
router.post('/signup', passport.authenticate('local-signup', {
successRedirect: '/login',
failureRedirect: '/error'
}));
router.get('/auth/facebook',
passport.authenticate('another-strategy'));
router.get('/auth/facebook/callback',
passport.authenticate('another-strategy', { failureRedirect: '/login' }),
function (req, res) {
// Successful authentication, redirect home.
res.redirect('/profile');
});
return router;
};