#59 username is now saved to user document on register
This commit is contained in:
parent
57d959a510
commit
e7ab3aadc1
4 changed files with 23 additions and 3 deletions
|
@ -7,21 +7,29 @@ import be.ugent.sel.studeez.common.ext.passwordMatches
|
|||
import be.ugent.sel.studeez.common.snackbar.SnackbarManager
|
||||
import be.ugent.sel.studeez.domain.AccountDAO
|
||||
import be.ugent.sel.studeez.domain.LogService
|
||||
import be.ugent.sel.studeez.domain.UserDAO
|
||||
import be.ugent.sel.studeez.navigation.StudeezDestinations.HOME_SCREEN
|
||||
import be.ugent.sel.studeez.navigation.StudeezDestinations.LOGIN_SCREEN
|
||||
import be.ugent.sel.studeez.navigation.StudeezDestinations.SIGN_UP_SCREEN
|
||||
import be.ugent.sel.studeez.screens.StudeezViewModel
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.FlowCollector
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.take
|
||||
import be.ugent.sel.studeez.R.string as AppText
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class SignUpViewModel @Inject constructor(
|
||||
private val accountService: AccountDAO,
|
||||
private val accountDAO: AccountDAO,
|
||||
private val userDAO: UserDAO,
|
||||
logService: LogService
|
||||
) : StudeezViewModel(logService) {
|
||||
var uiState = mutableStateOf(SignUpUiState())
|
||||
private set
|
||||
|
||||
private val username
|
||||
get() = uiState.value.username
|
||||
private val email
|
||||
get() = uiState.value.email
|
||||
private val password
|
||||
|
@ -59,8 +67,10 @@ class SignUpViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
launchCatching {
|
||||
accountService.signUpWithEmailAndPassword(email, password)
|
||||
openAndPopUp(LOGIN_SCREEN, SIGN_UP_SCREEN)
|
||||
accountDAO.signUpWithEmailAndPassword(email, password)
|
||||
accountDAO.signInWithEmailAndPassword(email, password)
|
||||
userDAO.save(username)
|
||||
openAndPopUp(HOME_SCREEN, SIGN_UP_SCREEN)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue