feature Keycloak Auth
This commit is contained in:
+39
-1
@@ -8,7 +8,12 @@ import androidx.compose.ui.text.font.FontWeight
|
||||
@Composable
|
||||
fun AppHeader(
|
||||
title: String,
|
||||
onNavigateToPing: (() -> Unit)? = null
|
||||
onNavigateToPing: (() -> Unit)? = null,
|
||||
onNavigateToLogin: (() -> Unit)? = null,
|
||||
onLogout: (() -> Unit)? = null,
|
||||
isAuthenticated: Boolean = false,
|
||||
username: String? = null,
|
||||
userPermissions: List<String> = emptyList()
|
||||
) {
|
||||
TopAppBar(
|
||||
title = {
|
||||
@@ -19,6 +24,7 @@ fun AppHeader(
|
||||
)
|
||||
},
|
||||
actions = {
|
||||
// Ping Service button
|
||||
onNavigateToPing?.let { navigateAction ->
|
||||
TextButton(
|
||||
onClick = navigateAction
|
||||
@@ -26,6 +32,38 @@ fun AppHeader(
|
||||
Text("Ping Service")
|
||||
}
|
||||
}
|
||||
|
||||
// Authentication buttons
|
||||
if (isAuthenticated) {
|
||||
// Show username with admin indicator if user has delete permissions
|
||||
username?.let { user ->
|
||||
val isAdmin = userPermissions.any { it.contains("DELETE") }
|
||||
Text(
|
||||
text = if (isAdmin) "👑 Hallo, $user (Admin)" else "Hallo, $user",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = if (isAdmin)
|
||||
MaterialTheme.colorScheme.tertiary
|
||||
else
|
||||
MaterialTheme.colorScheme.onPrimaryContainer
|
||||
)
|
||||
}
|
||||
onLogout?.let { logoutAction ->
|
||||
TextButton(
|
||||
onClick = logoutAction
|
||||
) {
|
||||
Text("Abmelden")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Show login button
|
||||
onNavigateToLogin?.let { loginAction ->
|
||||
TextButton(
|
||||
onClick = loginAction
|
||||
) {
|
||||
Text("Anmelden")
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
|
||||
+1
@@ -2,5 +2,6 @@ package at.mocode.clients.shared.navigation
|
||||
|
||||
sealed class AppScreen {
|
||||
data object Home : AppScreen()
|
||||
data object Login : AppScreen()
|
||||
data object Ping : AppScreen()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user