I have the following code to sign a person up in backend. I query a database to check if the username and email already exist. If so, I reject the promise. But, for whatever reason, I believe that the rest of the code is executed, and the person is signed up anyways. How do I break out of this promise?
export function signup(username, email, password) {
return new Promise((resolve, reject) => {
wixData.query('members')
.eq('title', username)
.find(options)
.then((results) => {
if (results.length > 0) {
reject('This username already exists!');
}
return wixData.query('members')
.eq('email', email)
.find(options);
})
.then((results) => {
if (results.length > 0) {
reject('This email already exists in the
collection!');
}
let toInsert = {
'title': username,
'email': email,
'password': password,
'wsmoStatus': false,
'ssmoStatus': false
};
wixData.insert('members', toInsert, options)
.then(() => {
authentication.register(email, password)
.then(() => {
resolve('success');
})
.catch((err) => {
removeItemMembers(email);
reject(err);
});
})
.catch((err) => {
reject(err);
});
})
.catch((err) => {
reject(err);
});
});
}
After I reject the promise, I think the program just keeps going and signs you up anyway. How do I fix that? Thanks in advance.