Android 在Firebase中使用匿名登录对Firestore上的用户进行身份验证
我有点迷路了,我正在编写一个android应用程序,它将为尚未登录的新用户提供从Android 在Firebase中使用匿名登录对Firestore上的用户进行身份验证,android,firebase,google-cloud-firestore,firebase-authentication,Android,Firebase,Google Cloud Firestore,Firebase Authentication,我有点迷路了,我正在编写一个android应用程序,它将为尚未登录的新用户提供从firestore读取一些数据的功能,因此我设置了匿名登录,并希望使用firebase auth对匿名用户进行身份验证,一旦用户通过身份验证,我想使用他的uid/cred访问firestore数据库 Firebase验证: mAuth = FirebaseAuth.getInstance(); mAuth.signInAnonymously() .addOnComple
firestore
读取一些数据的功能,因此我设置了匿名登录,并希望使用firebase auth
对匿名用户进行身份验证,一旦用户通过身份验证,我想使用他的uid/cred
访问firestore数据库
Firebase验证:
mAuth = FirebaseAuth.getInstance();
mAuth.signInAnonymously()
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
printWithDash("INSIDE onComplete");
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
printWithDash("SIGN IN SUCCESSFULL");
FirebaseUser user = mAuth.getCurrentUser();
printWithDash(user.toString()); // address
} else {
// If sign in fails, display a message to the user.
printWithDash("SIGN IN FAIL!!!");
}
}
});
db.collection("answers")
.add(jsonAnswers)
.addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
System.out.println("-----------------------------------------------------------------------------------------");
System.out.println("DocumentSnapshot added with ID: " + documentReference.getId());
System.out.println("-----------------------------------------------------------------------------------------");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
System.out.println("Error adding document " + e);
}
});
我是安卓开发新手,安卓应用上的身份验证是如何工作的?。如何使用我的匿名用户写入
firestore db
?仅放置请求.auth.uid!=无效
要能够读取和写入已登录的匿名用户,请执行以下操作:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
}
}
A匿名登录的用户也会经过身份验证。我了解到,匿名登录将在手机上保存您的用户信誉,请查看应用程序/您的应用程序下的设备文件资源管理器。因此,一旦我们进行匿名登录,用户将被视为经过身份验证,直到您执行
mAuth.signOut()代码>你好,尼亚索尔!这段代码中到底有什么东西不能按您期望的方式工作?这行是否System.out.println(“添加文档时出错”+e.getMessage())代码>在logcat中打印某些内容?现在我的权限被拒绝,但这是因为我设置的规则,问题是我在应用程序中作为匿名用户进行身份验证,但我想使用此用户ro写入firestore
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
}
}