2

I am building a kotlin app using FirebaseAuth and I want to add some custom rules to keep the user signed in for a time even if they are not using the app. All I could find in the docs related to this was for Web applications. https://firebase.google.com/docs/auth/web/auth-state-persistence

Is there anything like this in the docs for Android?

If not, is there a way I can get that functionality?

I was considering using SharedPreferences to store authentication state but I get the feeling there is a better way.

Dylon Jaynes
  • 166
  • 11

3 Answers3

3
public override fun onStart() {
super.onStart()
        val user = firebaseAuth.currentUser
        if (user != null) {
            //startActivity
        } else {
            Timber.i("Error")
        }
    }
3

You dont need to set it. Firebase currentuser stay there until you uninstall the application itself or log out. You just need to check whether the currentuser exist or not at the start of activity

Val currentUser = Firebase.auth.CurrentUser
if(currentUser1=null){
   Do something....
}
lelestacia
  • 201
  • 2
  • 9
  • This solved it! Even easier to test it out: if (Firebase.auth.CurrentUser == null) {print('user not logged in');} else {print('user is logged in');} – user395980 Nov 05 '22 at 09:54
0

So, I was not aware that firebase users stay signed in until logged out explicitly. Understanding this solved my problem as I didn't have to write code to handle keeping the user signed in.

Dylon Jaynes
  • 166
  • 11