How to call system functions before login?

Hi! I’ve created a function in realm that needs to be run before the login or even the registration. That means that app.currentUser is null. The problem is that I don’t find in the documentation how to do that.

I found this:

const result = await user.functions.sum(numA, numB);
const resultOfCallFunction = await user.callFunction("sum", myArgs); // alternate syntax to call a MongoDB Realm Function
  `Using the "functions.sum()" method: the sum of ${numA} + ${numB} = ${result}`
  `Using the "callFunction()" method: the sum of ${numA} + ${numB} = ${resultOfCallFunction}`

This works fine with authenticated users but how do I get system functions? The documentation keep talking about using the “system user”:

But I cannot find anywhere how I can use that user in my app. I just need to call that function.

1 Like

Have you consider calling this function as anonymous user ?

Hi! I can actually do that but the problem is that for every anon login it will create a record in the Users table from the realm Admin GUI. From doing some test I have already several pages of anon users.

is that the only way?

Another “solution” would be a login using ApiKeys but is that a good practive? Having every customer to log in using those keys for “global” task such as calling functions?

Hello @Mariano_Cano were you able to find a suitable solution here? I am dealing with a similar issue in needing to call a function before log in.

Hello, I think you have to use the https endpoint to be able to call functions without being authenticated, since you will only use a link to call the function you want

1 Like