Created
September 17, 2022 07:42
-
-
Save molidev8/95b8e65327a1b3350944fe3da0007a18 to your computer and use it in GitHub Desktop.
Firebase Authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private val auth: FirebaseAuth = FirebaseAuth.getInstance() | |
| // AuthState can be read to know if the user is logged in | |
| val authState = object : LiveData<FirebaseUser>() { | |
| private val authStateListener = FirebaseAuth.AuthStateListener { firebaseAuth -> | |
| value = firebaseAuth.currentUser | |
| } | |
| override fun onActive() { | |
| auth.addAuthStateListener(authStateListener) | |
| } | |
| override fun onInactive() { | |
| auth.removeAuthStateListener(authStateListener) | |
| } | |
| } | |
| fun getUserID() = auth.uid!! | |
| fun signOut() { | |
| auth.signOut() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment