Add authentication check to secure ping action and propagate auth state in PingScreen
Build and Publish Docker Images / build-and-push (., backend/infrastructure/gateway/Dockerfile, api-gateway, api-gateway) (push) Successful in 8m16s
Build and Publish Docker Images / build-and-push (., backend/services/ping/Dockerfile, ping-service, ping-service) (push) Successful in 7m38s
Build and Publish Docker Images / build-and-push (., config/docker/caddy/web-app/Dockerfile, web-app, web-app) (push) Successful in 2m58s
Build and Publish Docker Images / build-and-push (., config/docker/keycloak/Dockerfile, keycloak, keycloak) (push) Successful in 1m46s

This commit is contained in:
2026-03-16 23:35:49 +01:00
parent 04f8f2aae1
commit 4344d04ff9
3 changed files with 15 additions and 5 deletions
@@ -22,8 +22,10 @@ import at.mocode.frontend.core.designsystem.theme.Dimens
@Composable @Composable
fun PingScreen( fun PingScreen(
viewModel: PingViewModel, viewModel: PingViewModel,
onBack: () -> Unit = {} onBack: () -> Unit = {},
isAuthenticated: Boolean = false
) { ) {
viewModel.isAuthenticated = isAuthenticated
val uiState = viewModel.uiState val uiState = viewModel.uiState
// Wir nutzen jetzt das globale Theme (Hintergrund kommt vom Theme) // Wir nutzen jetzt das globale Theme (Hintergrund kommt vom Theme)
@@ -51,7 +53,7 @@ fun PingScreen(
.fillMaxHeight() .fillMaxHeight()
.padding(end = Dimens.SpacingS) .padding(end = Dimens.SpacingS)
) { ) {
ActionToolbar(viewModel) ActionToolbar(viewModel, isAuthenticated)
Spacer(Modifier.height(Dimens.SpacingS)) Spacer(Modifier.height(Dimens.SpacingS))
StatusGrid(uiState) StatusGrid(uiState)
} }
@@ -131,7 +133,7 @@ private fun StatusBadge(text: String, color: Color) {
} }
@Composable @Composable
private fun ActionToolbar(viewModel: PingViewModel) { private fun ActionToolbar(viewModel: PingViewModel, isAuthenticated: Boolean) {
// Wrap buttons to avoid overflow on small screens // Wrap buttons to avoid overflow on small screens
Row( Row(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
@@ -139,7 +141,7 @@ private fun ActionToolbar(viewModel: PingViewModel) {
) { ) {
DenseButton(text = "Simple", onClick = { viewModel.performSimplePing() }) DenseButton(text = "Simple", onClick = { viewModel.performSimplePing() })
DenseButton(text = "Enhanced", onClick = { viewModel.performEnhancedPing() }) DenseButton(text = "Enhanced", onClick = { viewModel.performEnhancedPing() })
DenseButton(text = "Secure", onClick = { viewModel.performSecurePing() }) DenseButton(text = "Secure", onClick = { viewModel.performSecurePing() }, enabled = isAuthenticated)
DenseButton(text = "Health", onClick = { viewModel.performHealthCheck() }) DenseButton(text = "Health", onClick = { viewModel.performHealthCheck() })
DenseButton( DenseButton(
text = "Sync", text = "Sync",
@@ -41,6 +41,8 @@ class PingViewModel(
var uiState by mutableStateOf(PingUiState()) var uiState by mutableStateOf(PingUiState())
private set private set
var isAuthenticated: Boolean = false
private fun addLog(source: String, message: String, isError: Boolean = false) { private fun addLog(source: String, message: String, isError: Boolean = false) {
val now = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()) val now = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())
val timeString = "${now.hour.toString().padStart(2, '0')}:${now.minute.toString().padStart(2, '0')}:${ val timeString = "${now.hour.toString().padStart(2, '0')}:${now.minute.toString().padStart(2, '0')}:${
@@ -108,6 +110,10 @@ class PingViewModel(
} }
fun performSecurePing() { fun performSecurePing() {
if (!isAuthenticated) {
addLog("SecurePing", "Not authenticated request blocked.", isError = true)
return
}
viewModelScope.launch { viewModelScope.launch {
uiState = uiState.copy(isLoading = true, errorMessage = null) uiState = uiState.copy(isLoading = true, errorMessage = null)
addLog("SecurePing", "Sending authenticated request...") addLog("SecurePing", "Sending authenticated request...")
@@ -36,6 +36,7 @@ fun MainApp() {
// Delta-Sync blueprint: resolve the Ping feature view model via Koin. // Delta-Sync blueprint: resolve the Ping feature view model via Koin.
val pingViewModel: PingViewModel = koinViewModel() val pingViewModel: PingViewModel = koinViewModel()
val loginViewModel: LoginViewModel = koinViewModel() val loginViewModel: LoginViewModel = koinViewModel()
val authState by authTokenManager.authState.collectAsState()
when (currentScreen) { when (currentScreen) {
is AppScreen.Landing -> LandingScreen( is AppScreen.Landing -> LandingScreen(
@@ -58,7 +59,8 @@ fun MainApp() {
is AppScreen.Ping -> PingScreen( is AppScreen.Ping -> PingScreen(
viewModel = pingViewModel, viewModel = pingViewModel,
onBack = { navigationPort.navigateToScreen(AppScreen.Home) } // Navigate back to Home onBack = { navigationPort.navigateToScreen(AppScreen.Home) },
isAuthenticated = authState.isAuthenticated
) )
is AppScreen.Profile -> AuthStatusScreen( is AppScreen.Profile -> AuthStatusScreen(