Firebase Rules - Cannot store user data on first login -
i pretty new firebase , having problem security rules. have android client registers or logs in new user. on user's first login, save info firebase so:
public void onauthenticated(authdata authdata) { //save user info firebase map<string, object> map = new hashmap<string, object>(); map.put("provider", authdata.getprovider()); ref.child("users").child(authdata.getuid()).updatechildren(map); }
(this called in onauthenticated() when authenticating user)
however, seems security rules not allowing user write database unless info stored. rules follows:
{ "rules": { "users":{ "$userid": { ".read": "auth.id == $userid && auth !== null", ".write": "auth.id == $userid && auth !== null" } } } }
also, if matters, here's illustration of info looks when stored:
how should modify rules allow client write user info 1 time authenticates server?
edit: after testing, appears these rules not allow user write user node, if exists.
you have typo in rules have:
".write": "auth.id == $userid && auth !== null"
that should auth.uid
, not auth.id
.
i null check first.
so:
".write": "auth !== null && auth.uid == $userid"
firebase firebase-security firebase-android
No comments:
Post a Comment