What's userId for in applyPermissions()?


#1

I created three admin users: user1, user2 and user3.
user1 is the owner of /v1/user1
user2 is the owner of /v1/user2
user3 is the owner of /v1/user3
user.applyPermissions({userId:’*’},’/v1/user1’,‘read’)… This will apply public read permissions on ‘/v1/user1’
user.applyPermissions({userId:‘user1’},’/v1/user1’,‘read’)… This will apply public read permissions on ‘/v1/user1’
user.applyPermissions({userId:‘user2’},’/v1/user2’,‘read’)… This will apply public read permissions on ‘/v1/user3’
Can you please explain more about userId property?
Also can you please give some examples about how metadataKey and metadataValue work? Thanks


#2

you shouldn’t use metadata, thats only for realm.


#3

https://realm.io/docs/javascript/latest/api/Realm.Sync.User.html
applyPermissions(condition, realmUrl, accessLevel)Promise
Changes the permissions of a Realm.

Parameters:
condition
Type: object
A condition that will be used to match existing users against. This should be an object, containing either the key ‘userId’, or ‘metadataKey’ and ‘metadataValue’.


#4

yeah, you shoud use userid, like everywhere else.


#5

It looks like no matter what value is for userId, it will apply permissions to public.
I tried a random userId(please see the following)

user.applyPermissions({userId:’asdfasd’},’/v1/user1’,‘read’)

Read permissions is applied on /v1/user1 on public.


#6

I don’t understand the purpose of using userId.

It looks like no matter what value is for userId, it will apply permissions to public.
I tried a random userId(please see the following)

user.applyPermissions({userId:’asdfasd’},’/v1/user1’,‘read’)

Read permissions is applied on /v1/user1 on public.


#7

How do you determine that read permissions are applied to the public?


#8

public_permission


#9

Please see the screenshot. It’s from Realm Studio.


#10

User permissions are cumulative. So if you gave everyone read permission, giving read permission to a specific user, would not remove the other permission. Can you try creating a new Realm and applying permissions to it in order to confirm it’s not an old permission change that is what’s causing confusion. You can also try giving that particular user write permissions and see if the public permissions change (they should not).