-1

I am trying to make a public realm that all users will have read permissions to. The realm team mentioned this capability in this webinar, but I am having trouble finding any documentation on how to do it.

Here is a nice image from the webinar that illustrates the types of realms that can be made in the object server. I am having trouble finding out how to make a public realm.

Realm Object Server Types of Synced Realms Diagram

Jake Cronin
  • 1,002
  • 13
  • 15

3 Answers3

3

Here are directions for doing what you want. Be aware that this feature has changed slightly since that webinar was presented. (We also need to improve our documentation, so thank you for asking this question!)

  1. Create an admin user. You can do this by creating a regular user, going to the web dashboard, and editing the user so that it is an administrator. If the user is an admin, upon logging in its isAdmin property should be true.

  2. Using your admin user, open a global Realm. A global Realm is one whose path doesn't contain ~, for example /myGlobalRealm versus /~/eachUserHasTheirOwnCopy. Note that this Realm is completely inaccessible to other users by default. If the Realm doesn't yet exist, the Realm Object Server will automatically create it. This will be your public Realm.

  3. Create an RLMSyncPermissionValue to grant read permissions to all users. This means specifying the path to your public Realm (/myGlobalRealm), as well as a user ID of *.

  4. Then call -[RLMSyncUser applyPermission:callback:] on your admin user with your new permission value, and ensure that the server properly set the permission.

  5. Try opening your public Realm using a different user, and make sure it works.

I hope this helps.

AustinZ
  • 1,787
  • 1
  • 13
  • 21
1

Swift Solution You can run this once in your simulator to create a global realm with default read/write permissions.

SyncUser.logIn(with: .usernamePassword(username: "ADMIN USERNAME", password: "ADMIN PASSWORD!"), server: URL(string: "Your Server URL")! { (user, error) in
            guard user != nil else{
                print(error)
                return
            }
            do{
                let globalRealm = try Realm(configuration: Realm.Configuration(syncConfiguration: SyncConfiguration(user: user!, realmURL: URL(string: "realm://<YOUR SERVER>:9080/GlobalRealm")!),  readOnly: false))
            }catch{
                print(error)
            }
            let permission = SyncPermissionValue(realmPath: "/GlobalRealm", userID: "*", accessLevel: SyncAccessLevel.write)
            user!.applyPermission(permission) { error in
                if let error = error{
                    print(error)
                }else{
                    user!.retrievePermissions { permissions, error in
                        if let error = error {
                            print("error getting permissions")
                        }else{
                            print("SUCCESS!")
                        }
                    }
                }
            }
        }
Jake Cronin
  • 1,002
  • 13
  • 15
0

Here is a server function to write a public realm:

const Realm = require('realm');
const server_url = 'realm://<Your Server URL>:9080'
const realmName = 'PublicRealm'
const REALM_ADMIN_TOKEN = "YOUR REALM ADMIN TOKEN"
const adminUser = Realm.Sync.User.adminUser(REALM_ADMIN_TOKEN);


var newRealm = new Realm({
    sync: {
        user: adminUser,
        url: server_url + '/' + realmName
    },
});

Paste the code into the function editor in the realm dashboard and run the function to create a public realm. You can modify the public realm by changing the properties in the realm constructor.

Jake Cronin
  • 1,002
  • 13
  • 15