Reputation: 1079
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?
Upvotes: 1
Views: 597
Reputation: 317402
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.
Upvotes: 1