Firebase auth的用户标识的字符串值,用于记录Firestore

您能为我的Android项目提供帮助吗?我正在尝试在firebase auth中获取currentUID,并且希望它在我的firestore的文档中显示字符串值。

db2.collection("Assessment").document(??).set(answer);
abc121212121212 回答:Firebase auth的用户标识的字符串值,用于记录Firestore

可以通过getUid实例的FirebaseUser方法来检索当前登录的用户ID,该方法可以通过FirebaseAuth#getCurrentUser来检索:

Java:

FirebaseAuth auth = FirebaseAuth.getInstance();
FirebaseUser user = auth.getCurrentUser();
String uid = user.getUid();
// Or alternatively,a one-liner (although the code complexity is higher)
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();

科特琳:

val auth = FirebaseAuth.getInstance()
val user = auth.currentUser // Note: This returns a nullable class
val uid = user?.uid
// Or alternatively,a one-liner (although the code complexity is higher)
val uid = FirebaseAuth.getInstance().currentUser?.uid
本文链接:https://www.f2er.com/3130370.html

大家都在问