简体   繁体   中英

Unable to structure a Firebase Database security rule properly

In my iOS app a user creates a username which has similar characteristics to a Twitter username. Once identified as being unique, it is persisted to the database with updateChildValues with the below signature: (username is JogBloggs in example).

     ["usernames/": ["joebloggs: \(user.uid)"]]

In my security rules in my fb database I want to create a rule that ensures the uid being uploaded is the same as the uid of the current user. how could I type a security rule to ensure this? my attempt, below, doesn't work.

     "root.child('usernames').child(newData.val()).val() == auth.uid"

I have the following structure in my Database

在此处输入图片说明

With these rules associated with :

Firebase安全性结构

Cheers

Ok if I could then I would delete this question!! Answer is very complex and challenging.....

    newData.val() == auth.uid

Complete structure with correct answer below

    "usernames": {  
    ".read": "auth != null",
    ".write": "auth != null && auth.token.name == null", 
            "$username": {
                ".validate": "$username.length >= 1 && $username.length <= 15 &&
                          !root.child('usernames').child(newData.val().toLowerCase()).exists() &&
                                    newData.val() == auth.uid" 
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM