userRepositoryImpl < /p>
Код: Выделить всё
override suspend fun isUserLoggedIn(): Boolean {
return try {
val token = getToken().firstOrNull()
if (token.isNullOrEmpty()) {
false
} else {
auth.retrieveUser(token)
auth.refreshCurrentSession()
saveToken()
true
}
} catch (e: Exception) {
Log.e("UserRepository", e.message.toString())
false
}
}
< /code>
splashviewmodel < /p>
@HiltViewModel
class SplashViewModel @Inject constructor(
val userRepository: UserRepository
) : ViewModel() {
private val _startDestination = MutableStateFlow(Screen.Onboarding1.route)
val startDestination = _startDestination.asStateFlow()
init {
viewModelScope.launch {
if (userRepository.isUserLoggedIn()) {
_startDestination.value = Graph.MAIN
} else {
_startDestination.value = Screen.Onboarding1.route
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... celled-wit