* fix(#688): route expired auth sessions to sign-in Adopt global 401 latch, WS disconnect, and Back/profile guards. * chore: clean up formatting noise * fix(ktlint): reorder imports to place java and kotlinx at end * fix(ktlint): place java.io.IOException at end of imports * test: fix NavBackStack type parameter in AuthenticationRoutingTest * test: add AuthSessionState tests to AuthLoginViewModelTest * fix(ktlint): fix import order in AuthLoginViewModelTest
This commit is contained in:
10 files changed
+217
-4
No files matched your search
@@ -28,6 +28,7 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.rememberDrawerState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
@@ -43,6 +44,7 @@ import androidx.navigation3.runtime.NavKey
|
||||
import androidx.navigation3.runtime.entryProvider
|
||||
import androidx.navigation3.ui.NavDisplay
|
||||
import com.m57.hermescontrol.data.local.AuthManager
|
||||
import com.m57.hermescontrol.data.local.AuthSessionState
|
||||
import com.m57.hermescontrol.data.ws.ConnectionStatus
|
||||
import com.m57.hermescontrol.data.ws.HermesWsClient
|
||||
import com.m57.hermescontrol.theme.LocalHermesStatusColors
|
||||
@@ -132,6 +134,14 @@ private fun appEntryProvider(
|
||||
|
||||
@Composable
|
||||
fun MainNavigation(sessionId: String? = null) {
|
||||
val signInRequired by AuthSessionState.signInRequired.collectAsState()
|
||||
LaunchedEffect(signInRequired) {
|
||||
if (signInRequired) {
|
||||
HermesWsClient.disconnect()
|
||||
NavigationController.resetTo(AuthLoginScreen)
|
||||
}
|
||||
}
|
||||
|
||||
val token by AuthManager.tokenFlow.collectAsState()
|
||||
val hasToken = !token.isNullOrBlank()
|
||||
val startScreen: NavKey = if (hasToken) ChatScreen else LandingScreen
|
||||
|
||||
Reference in new issue
Block a user