I'm building an Android app that queries a Firebase Cloud Firestore database, and for doing this, the user must be authenticated because of this rule:
match /{document=**} {
allow read: if request.auth != null;
}
However, after authenticating with Google inside of the app, a query is executed and fails giving the insufficient permissions message:
D/: Query failed: PERMISSION_DENIED: Missing or insufficient permissions.
Here's the code:
private fun firebaseAuthenticateGoogle(account: GoogleSignInAccount?) {
try {
val credential = GoogleAuthProvider.getCredential(account?.idToken, null)
mAuth.signInWithCredential(credential).addOnSuccessListener { i ->
val firestore = FirebaseFirestore.getInstance(mAuth.app)
firestore.collection("units").document("1").get()
.addOnSuccessListener {
Log.d(TAG, "Query was successful")
}
.addOnFailureListener { e ->
Log.d(TAG, "Query failed: " + e.message)
}
}
}
If I close the app and reopen it, it works fine, as if the user were only authenticated after closing the app. However, if I check if mAuth.currentuser == null
it returns false, so the user should be authenticated right after clicking the Sign In button...
question from:
https://stackoverflow.com/questions/65626629/firebase-authentication-only-works-after-closing-and-reopening-app 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…