0
Getcurrentuser() return null

I facing a problem with getcurrentuser() after signout Getinstance().signout In phone authentication Now currentuser return null how to overcome this?

I use phone authentication to login into the android app. Everything was working fine until when I use the "sign out" button using getinstance().signout And after that, when I login again using phone number, I could log into the app, but now I am getting error to get current, it returns null.

How to overcome this problem? I am stuck in it.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • So you say that once you sign out, the FirebaseUser object is null? – Alex Mamo Dec 28 '22 at 07:51
  • Yes..i dont know how to overcome this problem – Shyam Jewellers Dec 28 '22 at 09:22
  • Aside from my answer, I think that this [resource](https://medium.com/firebase-tips-tricks/how-to-create-a-clean-firebase-authentication-using-mvvm-37f9b8eb7336) will help. Here is the corresponding [repo](https://github.com/alexmamo/FirebaseAuthentication). – Alex Mamo Dec 28 '22 at 09:33
  • Please provide enough code so others can better understand or reproduce the problem. – Community Dec 29 '22 at 05:15

1 Answers1

0

When you call signOut() on an instance of FirebaseAuth:

Signs out the current user and clears it from the disk cache.

Which basically means that the FirebaseUser object becomes null. So what you're experiencing is normal behavior. So each time you want to use a FirebaseUser object make sure the user is authenticated. In code you should check that object against nullity. If you however want to take some action when a user signs out, then I recommend you to use an AuthStateListener, as explained in my answer from the following post:

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • Thanx sir…I appreciate your helpful nature but i solved it just to remove signout button because i could not understand – Shyam Jewellers Dec 28 '22 at 12:31
  • Sir will you please tell me how to create 3 minute timer which is same for all user. My timer is automatically reset whenever i change fragment – Shyam Jewellers Dec 28 '22 at 12:45
  • If you have any other question that derives from this one, then it's considered a new question and should be added separately. So please post a new question, here on StackOverflow, using its own [MCVE](https://stackoverflow.com/help/mcve), so I and other Firebase developers can help you. – Alex Mamo Dec 28 '22 at 13:12
  • Hey Shyam. Did my answer help? Can I help you with other information regarding the initial question? – Alex Mamo Jan 14 '23 at 09:04