Skip to content

Over-complicated authentication #90

Description

@eliasmalik

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions