-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
37 lines (33 loc) · 903 Bytes
/
routes.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
var path = require("path");
module.exports = function(app, passport, socket) {
app.get('/', function(request, response) {
if(request.isAuthenticated()) {
return response.redirect('/public/account');
} else {
response.sendFile(path.join(__dirname + '/public/index.html'));
}
});
// Route for logging out
app.get('/logout', function(request, response){
request.logout();
response.redirect('/');
});
// Google routes
// Route to Google to do authentication
app.get('/auth/google',
passport.authenticate('google', {scope: [
'profile',
'email'
]}
));
// Callback from Google after authenticating the user
app.get('/auth/google/callback',
passport.authenticate('google', {
failureRedirect: '/'
}),
function(request, response) {
// Successful login
return response.redirect('/public/account');
}
);
}