I have built two APIs using Mongo Realm for my app. One authorized app which handles potentially destructive operators, such as mutations. Most of the requests done from my frontend is made to an open, non-authorized app though, which handles all usual “get” requests.
I have made it so that the client logs in anonymously, keeps the returned tokens in a global store and then makes all requests to the open API using them. So far so good. The problem is, when I then check the App Users tab in the Realm UI, each request has made a new row in the view, each with a new user id. The same goes for when I check the logs in the Realm UI, the anon-user login is triggered the same amount of times as my requests. I wonder why this is. Shouldn’t requests made with the same access token be counted as the same users?
I’m a bit concerned, because even though the anon users that are older than 90 days get deleted, my app risk getting flooded with anon users… Would that affect my app?
I’m super confused with what you are trying to do actually.
The API you mentioned above, indeed, is used to generate a token for an anonymous user. But REST APIs created in 3rd party services => HTTP Service => Webhooks don’t need a token. You can secure these using:
nothing (so completely public)
secret parameter (not the best security but can be good enough)
So unless you are using the MongoDB Realm Admin REST APIs to manipulate the content of your Realm app, I don’t understand why you even need a token in the first place.
Usually the tokens are used when you want to query a GraphQL API created in Realm for example or use an SDK to send CRUD operations or aggregation following the rules defined in Realm.
If you are using a REST API to manipulate the data which is into your Atlas cluster, then you don’t need a token basically.
I’m sorry if I made it sound like I was trying to use the tokens to use the webhooks, that’s not what I meant! I’m using the webhooks separately, and it’s working like a charm.
Rather, what I meant asking for was the GraphQL requests that you mentioned. Even though I use the same token for all GraphQL queries that are made from the one client session, the Realm user log registers a new anonymous user for each GraphQL request. I wonder why that is.
1 for the user creation and 1 for each GraphQL query.
So… I wasn’t able to reproduce the behaviour you are seeing. Can you please double check your logs & code and make sure that you are not regenerating a new user + token for each GraphQL query your are sending?
You can filter your logs using the log type to identify them more easily:
Also you can see the “User ID” on each of the GraphQL query log entries so they should all be identical if you generate just one user.