feat: add Shaarli account config and 401 logout
Add a "Compte Shaarli" settings section to edit the server URL and API secret with online re-validation, plus a logout action. Detect 401 responses from the Shaarli API via SessionManager, clear stored credentials and return the user to the login screen.
This commit is contained in:
@@ -12,6 +12,8 @@ import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import androidx.navigation.navArgument
|
||||
import androidx.navigation.navDeepLink
|
||||
import com.shaarit.core.network.SessionManager
|
||||
import com.shaarit.core.storage.TokenManager
|
||||
import java.net.URLEncoder
|
||||
|
||||
sealed class Screen(val route: String) {
|
||||
@@ -60,6 +62,8 @@ sealed class Screen(val route: String) {
|
||||
@Composable
|
||||
fun AppNavGraph(
|
||||
startDestination: String = Screen.Login.route,
|
||||
sessionManager: SessionManager? = null,
|
||||
tokenManager: TokenManager? = null,
|
||||
shareUrl: String? = null,
|
||||
shareTitle: String? = null,
|
||||
shareDescription: String? = null,
|
||||
@@ -70,7 +74,24 @@ fun AppNavGraph(
|
||||
) {
|
||||
val navController = rememberNavController()
|
||||
val context = LocalContext.current
|
||||
|
||||
|
||||
// On a 401 from the Shaarli API, the stored API secret is stale (it changed server-side).
|
||||
// Wipe the credentials and send the user back to the login screen.
|
||||
if (sessionManager != null && tokenManager != null) {
|
||||
androidx.compose.runtime.LaunchedEffect(sessionManager) {
|
||||
sessionManager.unauthorized.collect {
|
||||
tokenManager.clearToken()
|
||||
tokenManager.clearApiSecret()
|
||||
val currentRoute = navController.currentBackStackEntry?.destination?.route
|
||||
if (currentRoute != Screen.Login.route) {
|
||||
navController.navigate(Screen.Login.route) {
|
||||
popUpTo(navController.graph.id) { inclusive = true }
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// If user is already logged in and has share data, navigate directly to Add screen
|
||||
val hasShareData = shareUrl != null || (isFileShare && shareTitle != null)
|
||||
androidx.compose.runtime.LaunchedEffect(hasShareData) {
|
||||
@@ -292,7 +313,13 @@ fun AppNavGraph(
|
||||
) {
|
||||
com.shaarit.presentation.settings.SettingsScreen(
|
||||
onNavigateBack = { navController.popBackStack() },
|
||||
onNavigateToDashboard = { navController.navigate(Screen.Dashboard.route) }
|
||||
onNavigateToDashboard = { navController.navigate(Screen.Dashboard.route) },
|
||||
onNavigateToLogin = {
|
||||
navController.navigate(Screen.Login.route) {
|
||||
popUpTo(navController.graph.id) { inclusive = true }
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user