aboutsummaryrefslogtreecommitdiff
path: root/shared/src/commonMain/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'shared/src/commonMain/kotlin')
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt22
1 files changed, 22 insertions, 0 deletions
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt
index 8f5ac56..ed65824 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt
@@ -19,11 +19,25 @@ class SessionController(
object PasswordMissing : LoginState()
object Failure : LoginState()
object Success : LoginState()
+ object SignOut : LoginState()
}
val loginStateFlow = MutableStateFlow<LoginState?>(null)
val userFlow = MutableStateFlow<User?>(null)
+ fun getSession() {
+ loginStateFlow.value = LoginState.Loading
+ GlobalScope.launch {
+ try {
+ userFlow.value = sessionApi.sessionGet()
+ Log.d("LoginViewModel", userFlow.value.toString())
+ loginStateFlow.value = LoginState.Success
+ } catch (e: Exception) {
+ loginStateFlow.value = LoginState.Failure
+ }
+ }
+ }
+
fun restoreSession() {
loginStateFlow.value = LoginState.Loading
GlobalScope.launch {
@@ -62,4 +76,12 @@ class SessionController(
}
}
}
+
+ fun logout() {
+ GlobalScope.launch {
+ loginStateFlow.value = LoginState.Loading
+ sessionApi.sessionDelete()
+ loginStateFlow.value = LoginState.SignOut
+ }
+ }
} \ No newline at end of file