How do I break out of a promise?

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.

First of all, chain your promises, instead of nesting them. It’ll make them easier to read and debug.

return promiseA()
.then(result=> {
  return doSomethingElse(result);
})
.then(newResult => {
  return promiseB(newResult);
})
.then(finalResult =>  {
  return 'This is the final res: ' + finalResult ;
})
.catch(err => err);

Make sure to use a return before every wixData query/insert etc…
Then repost the question.

See also: