简体   繁体   中英

What is the difference between FirebaseAuth and FirebaseUser classes' uid property?

When getting the current auth user ID from firebase on Android, what is the difference between getting it from the FirebaseAuth or the FirebaseUser class?

For example:

val uid1 = FirebaseAuth.getInstance().currentUser?.uid
val uid2 = FirebaseAuth.getInstance().uid

They seem to return the same value, is there any reason or use case to choose one over the other?

If you examine the bytecode very carefully, you will see that FirebaseAuth.getInstance().getUid() is implemented (essentially) like this:

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
return user == null ? null : user.getUid();

They are basically the same thing. Just use the one that you personally prefer.

I will point out, however, that FirebaseAuth.getInstance().getUid() does not show up anywhere in the documentation. So it doesn't seem like the recommended choice in any circumstance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM