bradtraversy / node_passport_login

Node.js login, registration and access control using Express and Passport
1.74k stars 1.3k forks source link

A logged in user should not be asked to login/register again? #30

Open gitp18 opened 5 years ago

gitp18 commented 5 years ago

After successful sign up, http://localhost:5000/users/login and http://localhost:5000/users/register should redirect to http://localhost:5000/dashboard page, until the user sign out.

bradtraversy commented 5 years ago

You are right. If you want to make a pull request I will check it out and accept

harmnot commented 5 years ago

I am using sequelize and it doesn't save the session, after I login and I go to login router again, it still on login form,

CloudBranch commented 5 years ago

Another thing to improve the UX would be to log the user in automatically after registering

in "routes/users.js" add this code

req.login(user, function(err) { if (err) { return next(err); } return res.redirect('/dashboard'); });

CloudBranch commented 5 years ago

          bcrypt.hash(newUser.password, salt, (err, hash) => {
            if (err) throw err;
            newUser.password = hash;
            newUser
              .save()
              .then(user => {

                req.login(user, function(err) {
                  if (err) { return next(err); }
                  return res.redirect('/dashboard');
                });

              })
              .catch(err => console.log(err));
          });
        }); ```
hackrx commented 4 years ago

If somebody finds solution for this then please comment out here