简体   繁体   中英

Firebase Authentication returns NULL for getCurrentUser()

When my Android app starts I check if the user is logged in and proceed. Later on I expect this line to always returns me the user object:

FirebaseAuth.getInstance().getCurrentUser()

That normally works but sometimes it returns null . Why is this? Is this normal? And how to handle it?

The documentation for getCurrentUser() is clear that it will return the currently logged in user, or null if there is none. If you're getting null here, that means no user is logged in.

If you can clearly demonstrate that it returns null when there is definitely a user logged in, that is a bug. Though I will say that this problem has never come up before, and it would massively break many applications if there was a bug here.

Consider adding an AuthStateListener to better understand when a user is logged in or not. Please read the documentation to better understand the edge cases where a user may be present, but not yet fully authenticated and available to the SDK. Using an AuthStateListener correctly deals with these cases.

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