akashyap2013 / MERN_Login_App_with_ResetEmail

In this project, we are going to create the MERN Login App with Reset Email Feature.
234 stars 162 forks source link

Can not REGISTER..... #10

Open Khansa03 opened 8 months ago

Khansa03 commented 8 months ago
ERROR

What do I do? it says could not register

nkayilovette03 commented 6 months ago

Instead of doing this as in the tutorials;

const existUsername = new Promise((resolve, reject) => {
      UserModel.findOne({ username }, function (err, user) {
        if (err) reject(new Error(err));
        if (user) reject({ error: "Please use unique username" });
        resolve();
      });
      }); 

Instead handle this with the code below by using the async await method

const existUsername = await UserModel.findOne({
      username,
      function(err, user) {
        if (err) reject(new Error(err));
        if (user) reject({ error: "Please use unique username" });
      },
    });

Hopefully this works for you. Thank me later