2017-06-05 114 views
1

我正嘗試在用戶的userid下添加文本(32424234)到我的firebase中,但它不允許我這樣做。Firebase數據庫身份驗證

這是在火力

{ 
    "rules": { 
    "users": { 
     "$uid": { 
     ".read": "$uid == auth.uid", 
     ".write": "$uid == auth.uid" 
     } 
    } 
    } 
} 

我的規則部分這是我的Java代碼:

public void kullanicikontrol(String kullaniciadi){ 
     mRootRef = new Firebase("https://xxxx.firebaseio.com/users"); 
     Firebase chieldref = mRootRef.child(kullaniciadi); 
     chieldref.setValue("32424234"); 
} 

如果我改變像」 .read‘規則:真正的’有喜歡的截圖沒問題如下:

enter image description here

,但我不希望什麼。我做錯了?

+0

您在下面評論中添加的代碼使用「新」Firebase SDK(在I/O ** 2016 **上推出)。您的問題中的代碼使用了較早的Firebase SDK。較新SDK中的身份驗證不適用於使用舊SDK的數據庫訪問。要解決這個問題,請更新您的數據庫代碼以使用新的SDK:https://firebase.google.com/docs/database/ –

回答

1

在firebase中.read和.write是讀取寫入權限。如果將它設置爲true,那麼它將允許所有用戶。

您可以通過以下鏈接 https://firebase.google.com/docs/auth/web/manage-users

我希望這將幫助您創建新的用戶和認證。

+0

我得到的uid與您提到的帖子有點不同。 FirebaseUser user = FirebaseAuth.getInstance()。getCurrentUser(); if(user!= null){ //名稱,電子郵件地址和個人資料照片URL String name = user.getDisplayName(); String email = user.getEmail(); Uri photoUrl = user.getPhotoUrl(); String uid = user.getUid(); kullanici =新數據庫(); kullanici.kullanicikontrol(uid); }它錯了嗎? – Faruk

+0

Firebase項目特有的用戶ID。如果您有後端服務器,請勿使用此值對其進行身份驗證。使用User.getToken()來代替。 – DreamCoder