fix update token

This commit is contained in:
2026-09-15 12:34:07 +03:00
parent eeaca6c1bd
commit 218659fbd8
5 changed files with 47 additions and 24 deletions
@@ -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")
@@ -36,9 +36,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<data
android:scheme="gigawear"
android:host="chat" />
</intent-filter>
</activity>
@@ -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()
}
}
@@ -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<Route>(context) {
private val scope = coroutineScope()
override val initStack: List<Route> = listOf(Route.RoutingScreen())
override val serializer: KSerializer<Route> = 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
)
}
}
@@ -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<Child.RoutingChild, Route.RoutingScreen, Route> {
override fun create(
route: Route.RoutingScreen,
child: ComponentContext,
root: RouteNavigator<Route>
): Child.RoutingChild {
val comp = RoutingComponent(child, tokenStorage, healthCheck) {
val comp = RoutingComponent(child, tokenStorage) {
root.navReplace(it)
}
return Child.RoutingChild(comp)