bradtraversy / node_passport_login

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

Register #71

Open ghost opened 4 years ago

ghost commented 4 years ago

After I register a user the page is just loading and then says that there is a user using that email already, and it doesn't redirect you to the login page.

XBShu commented 3 years ago

If the problem is that it says that the user exists when it doesn't, go to your MongoDB cluster and check your users collection to make sure it's not there.

If you want to redirect to the login page you should insert res.render('login', {errors}) instead of res.render('register') as shown in the tutorial. After you have confirmed that the email already exists in the databse. It should look something like this:

//Register user
router.post('/register', (req,res) => {
    //...code

    //If all the data entered is correct, proceed to check if the user with the email exists
    } else {
        User.findOne({email: email})
            .then(user => {
                if(user) {
                    errors.push({message: "User with that email already exists, please login"});
                    res.render('register', {errors});
                }

    //...rest of code
hcsec20 commented 3 years ago

cannot open register page as it says "Error: Could not find the include file "("./partials/messages");"