return error when register user with used email:

This commit is contained in:
Adolfo Reyna
2021-09-23 22:43:45 -07:00
parent 19b699e015
commit 83941c59d5
2 changed files with 11 additions and 8 deletions

View File

@@ -76,21 +76,21 @@ DB.getDB.then((DB)=>{
if(!username || !password || !email) return res.json({status: "fail"})
//const hashedPassword = await bcrypt.hash(password, 10);
const hashedPassword = await bcrypt.hash(password, 10);
const success = await DB.newUser({
username: username,
email: email,
const response = await DB.newUser({
username: username.toLowerCase(),
email: email.toLowerCase(),
password: hashedPassword
});
if(success){
if(!response.toLowerCase){
let user = {
userid: success.insertedId,
userid: response.insertedId,
profile: profile,
}
const userObj = new Profile(user);
await DB.newProfile(userObj);
return await login(req, res);
}
res.redirect('/signup');
return res.json({status: response})
}
app.route('/signup').get(async (req, res) => {
return await signup(req, res);
@@ -125,7 +125,6 @@ DB.getDB.then((DB)=>{
res.cookie('session_id', doc.insertedId, cookiesOptions);
//Chooses the most recent update profile
const latestProfile = await DB.latestProfile(user._id);
console.log("latestProfile", latestProfile)
res.cookie('profile_id', latestProfile._id, cookiesOptions);
return res.json({
status: "ok",