-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuser.js
43 lines (32 loc) · 834 Bytes
/
user.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
module.exports = (passport, app, User) => {
app.get('/auth/google', passport.authenticate('google',
{
scope: ['profile', 'email'],
callbackURL : '/auth/google/callback',
accessType: 'offline',
prompt: 'consent'
})
);
app.get('/auth/google/callback', passport.authenticate('google', {
callbackURL : '/auth/google/callback'
}), (req, res) => {
if(req.user.name){
res.redirect('/dashboard');
}else{
User.findById(req.user._id).then((user) => {
user.admin = true;
user.save().then(() => {
res.redirect('/dashboard');
});
})
}
}
);
app.get('/api/logout', (req, res) => {
req.logout();
res.redirect('/');
});
app.get('/api/current_user', (req, res) => {
res.send(req.user);
})
}