diff --git a/apps/giga-wear/backend/src/main/kotlin/ru/shadowsparky/gigawear/backend/di/DbModule.kt b/apps/giga-wear/backend/src/main/kotlin/ru/shadowsparky/gigawear/backend/di/DbModule.kt
index f81d91c..0f2dab0 100644
--- a/apps/giga-wear/backend/src/main/kotlin/ru/shadowsparky/gigawear/backend/di/DbModule.kt
+++ b/apps/giga-wear/backend/src/main/kotlin/ru/shadowsparky/gigawear/backend/di/DbModule.kt
@@ -16,7 +16,7 @@ class DbModule {
fun provideSqlDriver(envFetcher: EnvFetcher): SqlDriver {
return PGSimpleDataSource().apply {
val db = envFetcher.get("POSTGRES_DB", "gigawear")
- val uri = envFetcher.get("VIDEOBOX_SERVER_URI", "localhost")
+ val uri = envFetcher.get("DB_SERVER_URI", "localhost")
val login = envFetcher.get("POSTGRES_USER", "login")
val pass = envFetcher.get("POSTGRES_PASSWORD", "password")
setUrl("jdbc:postgresql://$uri:5432/$db")
diff --git a/apps/giga-wear/client/src/main/AndroidManifest.xml b/apps/giga-wear/client/src/main/AndroidManifest.xml
index 7a39263..6e6921e 100644
--- a/apps/giga-wear/client/src/main/AndroidManifest.xml
+++ b/apps/giga-wear/client/src/main/AndroidManifest.xml
@@ -36,9 +36,6 @@
-
diff --git a/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/data/RefreshTokenActionImpl.kt b/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/data/RefreshTokenActionImpl.kt
index 4299204..41b730f 100644
--- a/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/data/RefreshTokenActionImpl.kt
+++ b/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/data/RefreshTokenActionImpl.kt
@@ -6,6 +6,7 @@ import io.ktor.client.request.post
import io.ktor.client.request.setBody
import org.koin.core.annotation.Factory
import ru.shadowsparky.gigawear.common.AuthRepository
+import ru.shadowsparky.gigawear.common.UpdateTokenRequest
import ru.shadowsparky.http.domain.RefreshTokenAction
import ru.shadowsparky.http.domain.TokenInfo
@@ -13,7 +14,7 @@ import ru.shadowsparky.http.domain.TokenInfo
class RefreshTokenActionImpl : RefreshTokenAction {
override suspend fun refresh(client: HttpClient, refreshToken: String): TokenInfo {
return client.post("$ENDPOINT/${AuthRepository.UPDATE_TOKEN_PATH}") {
- setBody(refreshToken)
+ setBody(UpdateTokenRequest(refreshToken))
}.body()
}
}
diff --git a/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/GigaWearRootComponent.kt b/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/GigaWearRootComponent.kt
index 61f5f08..51a5132 100644
--- a/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/GigaWearRootComponent.kt
+++ b/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/GigaWearRootComponent.kt
@@ -1,24 +1,59 @@
package ru.shadowsparky.gigawear.presentation
import com.arkivanov.decompose.ComponentContext
+import com.arkivanov.essenty.lifecycle.coroutines.coroutineScope
+import com.arkivanov.essenty.lifecycle.doOnStart
+import kotlinx.coroutines.Job
+import kotlinx.coroutines.ensureActive
+import kotlinx.coroutines.flow.firstOrNull
+import kotlinx.coroutines.launch
import kotlinx.serialization.KSerializer
import org.koin.core.Koin
import org.koin.core.annotation.Factory
+import ru.shadowsparky.gigawear.domain.HealthCheck
import ru.shadowsparky.gigawear.presentation.nav.Route
+import ru.shadowsparky.http.domain.TokenStorage
import ru.shadowsparky.ui.nav.RootComponent
class GigaWearRootComponent(
- context: ComponentContext
+ context: ComponentContext,
+ private val tokenStorage: TokenStorage,
+ private val healthCheck: HealthCheck
) : RootComponent(context) {
+ private val scope = coroutineScope()
override val initStack: List = listOf(Route.RoutingScreen())
override val serializer: KSerializer = Route.serializer()
override val koin: Koin = ru.shadowsparky.koin
+
+ init {
+ var job: Job? = null
+ lifecycle.doOnStart {
+ job?.cancel()
+ job = scope.launch {
+ if (tokenStorage.token.firstOrNull() != null) {
+ runCatching {
+ healthCheck.healthCheck()
+ }.onFailure {
+ ensureActive()
+ tokenStorage.clear()
+ navReplace(Route.AuthScreen())
+ }
+ }
+ }
+ }
+ }
}
@Factory
-class RootComponentFactory {
-
+class RootComponentFactory(
+ private val tokenStorage: TokenStorage,
+ private val healthCheck: HealthCheck
+) {
fun create(context: ComponentContext): GigaWearRootComponent {
- return GigaWearRootComponent(context)
+ return GigaWearRootComponent(
+ context,
+ tokenStorage,
+ healthCheck
+ )
}
}
diff --git a/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/routing/RoutingComponent.kt b/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/routing/RoutingComponent.kt
index a7eb7f8..8e1abb1 100644
--- a/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/routing/RoutingComponent.kt
+++ b/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/routing/RoutingComponent.kt
@@ -2,12 +2,10 @@ package ru.shadowsparky.gigawear.presentation.routing
import com.arkivanov.decompose.ComponentContext
import com.arkivanov.essenty.lifecycle.coroutines.coroutineScope
-import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.launch
import org.koin.core.annotation.Factory
import org.koin.core.annotation.Named
-import ru.shadowsparky.gigawear.domain.HealthCheck
import ru.shadowsparky.gigawear.presentation.nav.Child
import ru.shadowsparky.gigawear.presentation.nav.Route
import ru.shadowsparky.http.domain.TokenStorage
@@ -17,25 +15,18 @@ import ru.shadowsparky.ui.nav.RouteNavigator
class RoutingComponent(
private val context: ComponentContext,
private val tokenStorage: TokenStorage,
- private val healthCheck: HealthCheck,
private val navigateTo: (Route) -> Unit
) : ComponentContext by context {
private val scope = coroutineScope()
init {
scope.launch {
- if (tokenStorage.token.firstOrNull() != null) {
- runCatching {
- healthCheck.healthCheck()
- navigateTo(Route.ChatScreen())
- }.onFailure {
- ensureActive()
- tokenStorage.clear()
- navigateTo(Route.AuthScreen())
- }
+ val screen = if (tokenStorage.token.firstOrNull() != null) {
+ Route.ChatScreen()
} else {
- navigateTo(Route.AuthScreen())
+ Route.AuthScreen()
}
+ navigateTo(screen)
}
}
}
@@ -44,14 +35,13 @@ class RoutingComponent(
@Named(Route.ROUTING)
class RoutingComponentFactory(
private val tokenStorage: TokenStorage,
- private val healthCheck: HealthCheck
) : ComponentFactory {
override fun create(
route: Route.RoutingScreen,
child: ComponentContext,
root: RouteNavigator
): Child.RoutingChild {
- val comp = RoutingComponent(child, tokenStorage, healthCheck) {
+ val comp = RoutingComponent(child, tokenStorage) {
root.navReplace(it)
}
return Child.RoutingChild(comp)