'Firebase user logs out in android app and get current_user returns null

We have developed an android app that uses firebase for a chat. Firebase user logs in during the initial login process with opt authentication. The firsbase reads and writes into firebase realtime database for chat messages.

When the user goes to the chat tab, we call the function FirebaseAuth.getInstance().getCurrentUser() to read the current user and then the chat process starts working.

This process works fine most of the time but sometimes, the chat does not load. When we investigated, we found that firebase user suddenly gets disconnected/logout. When we try FirebaseAuth.getInstance().getCurrentUser(), it returns null for the user

It happens randomly and we have not been able to find out the reason behind the user getting null. When the app is not able to get the current user, the chat does not load.

Can someone give some clue on what could be the reason behind this user getting null randomly?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source