customFunction error

Iḿ trying to auth user with custom function, the client is an android mobile created with React Native. when i call login realm app function (app.logIn(credentials)) i get this error: {“code”: 47, “message”: “expected auth function result to be of type string or primitive.D but found primitive.Undefined”}.
this is my function in mongodb realm:
exports = async function (userId) {
console.log(userId);
const users = context.services.get(“mongodb-atlas”).db(“inventario”).collection(“userprofiles”);
const user = await users.findOne({ id: userId });

if (user) {
  return user._id.toString();
}

};
And in the authFunc settings the authentication method is system.