|
passport.authenticate('github', (err, user, info) => { |
|
if (err) { return next(err); } |
|
if (!user) { return res.redirect('/'); } |
|
req.logIn(user, (err) => { |
|
if (err) { return next(err); } |
|
if (info.message === 'Not FAC member') { |
|
return res.redirect('/notmember'); |
|
} else if (info.message === 'Login successful') { |
|
req.session.registeredProfile = true; |
|
return res.redirect(`/myprofile/${req.user.github_id}/mydetails/edit`); |
|
} else if (info.message === 'Signup successful') { |
|
req.session.registeredProfile = false; |
|
return res.redirect(`/myprofile/${req.user.github_id}/mydetails/edit`); |
|
} |
|
}); |
This doesn't really seem necessary. You're determining if the user has logged in or signed up, but that information is not used in the view. Is that a feature you still want to develop? If so, I would suggest it would simplify things if you just added a flag to your user model that indicated whether they have previously created an account.
Then the above code could just be:
passport.authenticate('github', { failureRedirect: '...', successRedirect: '...' })
The updateUserSession then also becomes unnecessary. protectedRoute can simply refer to isAuthenticated().
This would also slightly simplify my suggested solution in #89
stackMatch/src/controllers/index.js
Lines 32 to 46 in a84d27c
This doesn't really seem necessary. You're determining if the user has logged in or signed up, but that information is not used in the view. Is that a feature you still want to develop? If so, I would suggest it would simplify things if you just added a flag to your user model that indicated whether they have previously created an account.
Then the above code could just be:
The
updateUserSessionthen also becomes unnecessary.protectedRoutecan simply refer toisAuthenticated().This would also slightly simplify my suggested solution in #89