Realm Custom function authentication taking too long

I have implemented a custom function for user authentication in Realm and for login I have:

let authenticatedUser = await collection.findOne({ userEmail: givenEmail });
if(!authenticatedUser) 
  throw Error("User with email \"" + givenEmail + "\" does exist!");

let match = await bcrypt.compare(givenPassword, authenticatedUser.userPassword);
      
if(match)
  return { id: authenticatedUser._id.toString(), email: authenticatedUser.userEmail };
else
  throw Error("Password did not match");

The implementation works but it takes too long (1m 30s every time), which will be quite annoying to users, so I am wondering why is it taking too long. Is there something I am doing wrong?( when signing the users up, I generated the bcrypt passwords using a salt of 10 if that matters)

I decided to use Custom function auth because I didn’t know how to use the recommended email/password auth and map the authenticated user to my “Users” collection in my atlas database. I’d appreciate a guide to using the email/password auth as well