In Realm rules, under owner I have tried lots of variations, including hardcoding the user ID to validate. Unfortunately, I can’t get the rule to work.
{
"user": "%%user.id"
}
Hardcoded test
{
"user": "<SOME_USER_OBJECT_ID>"
}
I read on another thread that this could be due to the client passing the user as an ObjectId and not a String. However, if I try a String this doesn’t work as GraphQL is expecting an ObjectId.
Can you link your app URL so I can take a closer look at your schema/rules?
If user is a field with an ObjectId type in your schema and you’re not using custom user data, this should work unless there are other rules preventing this or a typo in the schema/user. I believe the reason hardcoding the object Id isn’t working either is because it is being treated as a string, and thus not passing the rule.
Hey Niall - similar to the post you read said, %%user.id is actually a string. Therefore, you’re comparing an objectId to a string and it’s not passing the rule.
To get around this you can use a function (although we are introducing expressions such as %%oidToString and %%stringToOid very soon)
It needs to be added in the “Functions” section (accessed via the side nav). The name of the function has to be the same as what is referred to in your rules (mine was called equalStrings) and be a System function, the logic has to return whether the two strings (or objectIds) are equal.
I mean is this function necessary still to match a user up with their records using graphql. Do I still need this function to match up a user with their own records, or does it now properly handle user id strings when comparing? Specifically I’m sending:
Looking at your app, it seems like you copied and pasted from the snippet above, but you would have to replace %%root.user to %%root.user_id since that is what your field is called. (in the first example it was user).
Is this still necessary though? Earlier in the thread you mentioned “… we are introducing expressions such as %%oidToString and %%stringToOid very soon” as a replacement.