Realm device sync "Action on service 'mongodb-atlas' forbidden: no rules have been configured for this service" error

I’m developing a mobile app using Swift and Realm database.

I configured Realm Device Sync and tried to add custom user data to a cluster I created.

Even though I watched dozens of tutorials about realm permissions I still can’t figure out what’s wrong with the in-app permissions

here is the authentication function I am using to add Custom User Data

func login() {
        isLoading = true
        errorMessage = nil
        
        
        let credentials = Credentials.emailPassword(email: username, password: password)
        
        DispatchQueue.main.async {
            app.login(credentials: credentials) { [weak self] result in
                switch (result) {
                case .failure(let error):
                    print(String(describing: error))
                    self?.errorMessage = error.localizedDescription
                    
                case .success(let user):
                    if user.customData.isEmpty {
                        let client = user.mongoClient("mongodb-atlas")
                        let database = client.database(named: "UserAPI")
                        let collection = database.collection(withName: "Users")
                        // Insert the custom user data object
                        let customUserData: Document = [
                            "_id": AnyBSON(user.id),
                            "email": .string(self!.email),
                            "province": .string(self!.province),
                            "_partition": .string(user.id)
                        ]
                        collection.insertOne(customUserData) {result  in
                            switch result {
                            case .failure(let error):
                                print("Failed to insert document: \(error.localizedDescription)")
                            case .success(let newObjectId):
                                print("Inserted custom user data document with object ID: \(newObjectId)")
                            }
                        }
                    }
                }
                self?.isLoading = false
            }
        }
    }

But when I try to create a new user, it successfully creates one. The problem is, when it comes things comes to adding the Custom User Data it returns an error like this:

Failed to insert document: no rule exists for namespace 'UserAPI.Users'

and when I check the MongoDB logs, I can see the error in more detail:
Error:

Action on service ‘mongodb-atlas’ forbidden: no rules have been configured for this service
{
“name”: “insertOne”,
“arguments”: [
{
“database”: “UserAPI”,
“collection”: “Users”,
“document”: {
“_id”: “62aaf9ab775b8b21d2343783”,
“_partition”: “62aaf9ab775b8b21d2343783”,
“email”: “selam456qwe”,
“province”: “”
}
}
],
“service”: “mongodb-atlas”
}
Function Call Location:
DE-FF
Compute Used:
91734180 bytes•ms
Remote IP Address:
31.223.94.210

my Custom User Data settings:
(I saw an error like I can’t upload more than one embeded images so I will write them instead:)

Cluster Name:
mongodb-atlas

Database Name:
UserAPI

Collection Name:
Users

User ID Field: _id

and my app permissions:

any help would be appriciated, I’m struggling with this error for 3 days

I read the documentations about syncing and partitioning a couple of times but still can’t figure what’s wrong,

thanks in advance.

wrong image, sorry.

Hi, could you post the URL to your application on realm.mongodb.com? (It is safe, only employees can read it). I suspect one of the issues may be that you may not have a schema defined on that table, but I can take a peek under the hood.

Thanks,
Tyler