Skip to content

Instantly share code, notes, and snippets.

@adrianhall
Created September 13, 2018 19:35
Show Gist options
  • Save adrianhall/7e9f28a24bf97c08d330689aa648b156 to your computer and use it in GitHub Desktop.
Save adrianhall/7e9f28a24bf97c08d330689aa648b156 to your computer and use it in GitHub Desktop.
class AuthenticatorViewModel(private val identityRepository: IdentityRepository) : ViewModel() {
/**
* Current user record, or null if the user is not logged in
*/
val currentUser: LiveData<User?> = identityRepository.currentUser
/**
* Stored user name, or null if the user has never logged in
*/
val storedUsername: LiveData<String?> = identityRepository.storedUsername
/**
* Initiate each flow in the authentication process
*/
fun initiateSignin(handler: IdentityHandler) = identityRepository.initiateSignin(handler)
fun initiateSignup(handler: IdentityHandler) = identityRepository.initiateSignup(handler)
fun initiateForgotPassword(handler: IdentityHandler) = identityRepository.initiateForgotPassword(handler)
/**
* The sign-out process doesn't need to do anything other than complete as the
* process should either fail or be successful, in which case the currentUser
* will either update or not.
*/
fun signOut() = identityRepository.initiateSignout { _, _, _ -> run { /* Do Nothing */ }}
/**
* Update the stored username
*/
fun updateStoredUsername(username: String?) = identityRepository.updateStoredUsername(username)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment