Trying to search user details in realm

I would like to create a search function which would look for a user’s email address before creating it. And if the email address exist, I would like to throw an error. I’ve tried looking around mongoDB’s realm api documentation and haven’t succeeded. Please look at the code below to give you an idea on what I’m trying to do:

const email = "someone@example.com";
const password = "Pa55w0rd";

const registerHandler = () => {
//first I would like to search and check if the email exists

//Search & filter function
if(/**email address exists**/){
   return console.log('Email address already exists');
}

//Create new user if email does not exist
await app.emailPasswordAuth.registerUser({ email, password });
}

However I have no clue on where to start and the realm dependency doesn’t give me auto complete with typescript, so I’m unable to see what options are available.

The answer will vary somewhat depend on the use case;

Are you storing the users email address in Realm as well or just as part of the Auth object. It’s pretty common to also store it in Realm with other custom user data - email address, favorite food, shoe size, etc.

The other issue is that in order to search you “must be” authenticated (as a security measure); a new user isn’t auth’d so they wouldn’t be able to search. “must be” meaning: so just any ole person doesn’t download all of the email addresses for an instant spam list.

Last thing is that Realm auth won’t allow duplicate email addresses and will throw an error if it already exists - so you may just be able to handle that case in the register user function.

Can you tell us a bit more about your use case?

Is there a list of errors that realm throws in the documentation, e.g creating a duplicate email, what type of error will it show?.

Use case:
We want use offline first applications in my country as internet connection is highly unpredictable and would like to use realm sync to sync the data whenever he’s connected to the internet. When a user register, we would like to store the persons email, password, and contact number. As a security measure, whenever a users creates a new account we would like to check if email and contact number already exist. We want to limit the number of fake accounts that can be created.

First, see the github code for func registerUser(email: String, password: String) -> Future<Void, Error>

You can get the specific error from NSError but there is a list of error codes - I am not seeing at at the moment. Perhaps a Realmer can link it?