1

ファイアストアのデータを取得するルールを確立しようとしています。これは、Googleがクライアントにログインしてアクセスできます。私はこのルールを使用しているとき は、だから私が直面してる問題があるfirestore auth rule:Googleのクライアントにログインしました

match /helpers/customer/data/{document=**}{ 
    allow read: if request.auth != null; 
} 

エラーがlogcatでポップ

ONFAILURE: Errorcom.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED:不足または不十分なアクセス許可。私はパスが書き込みであることを意味し

match /helpers/customer/data/{document=**}{ 
    allow read: if true; 
} 

を使用していたときに

もそれだけで働いています。

GoogleSignInAccount acct = GoogleSignIn.getLastSignedInAccount(this); 

    if(acct != null){ 
     Log.i(TAG, "onCreate: Database Working"); 
     mFirestoreDB 
       .get() 
       .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() { 
        @Override 
        public void onComplete(@NonNull Task<QuerySnapshot> task) { 
         if (task.isSuccessful()) { 
          for (DocumentSnapshot document : task.getResult()) { 
           Log.d(TAG, document.getId() + " => " + document.getData()); 
          } 
         } else { 
          Log.d(TAG, "Error getting documents: ", task.getException()); 
         } 
        } 
       }); 
    }else{ 
     Log.i(TAG, "onCreate: Database not Working"); 
    } 

私が必要とするのは、ログインしたユーザーのみがアクセスできるルールです。

+0

エラーメッセージを表示するために必要な最小限のコードを含めるように質問を更新できますか? –

+0

私はクエストインを更新しました – Ashish

+0

'mFirestoreDB'はどのように初期化しますか?特定のコレクションを指していますか? –

答えて

1

GoogleでログインしてもFirebaseで自動的にユーザーにサインインされるわけではありません。また、セキュリティルールの変数セットがauthになる前に、Firebase認証でサインインする必要があります。 Firebase documentation in signing in with Googleから

private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { 
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId()); 

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); 
    mAuth.signInWithCredential(credential) 
      .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 
       @Override 
       public void onComplete(@NonNull Task<AuthResult> task) { 
        if (task.isSuccessful()) { 
         // Sign in success, update UI with the signed-in user's information 
         Log.d(TAG, "signInWithCredential:success"); 
         FirebaseUser user = mAuth.getCurrentUser(); 
         updateUI(user); 
        } else { 
         // If sign in fails, display a message to the user. 
         Log.w(TAG, "signInWithCredential:failure", task.getException()); 
         Toast.makeText(GoogleSignInActivity.this, "Authentication failed.", 
           Toast.LENGTH_SHORT).show(); 
         updateUI(null); 
        } 

        // ... 
       } 
      }); 
} 

しかし、私はあなたが私がリンクされ、ページ全体を読むことをお勧めします。

+0

ありがとう、それは働いた – Ashish

関連する問題