routes.js
975 Bytes
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
44
45
46
47
48
49
/**
* Add following code to routes() function in
* your ./config/routes.js file.
*/
var passport = require('passport')
// auth route
app.get('/auth/google', function(req,res,next) {
// add remember me details etc. here
next()
},
passport.authenticate('google', { failureRedirect: '/', failureFlash: true }),
function(req, res) {
res.redirect('/')
});
// auth callback
app.get('/auth/google/callback',
passport.authenticate( 'google', {
failureRedirect: '/'
}),
function(req, res, next) {
var redirectTo = req.session.redirectTo;
// Successful authentication, redirect to dashboard page.
if ( redirectTo ) {
req.session.redirectTo = null
res.redirect(redirectTo)
} else {
res.redirect('/logged-in')
}
}
);
// log out
app.get('/logout', function(req, res){
req.logout()
res.redirect('/')
});
// sample log-in message
app.get('/logged-in', function(req, res){
req.send(200, 'Hey!')
});