-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Impl web local storage * WIP: Session * Support more LocalStorage operations * WIP: Google auth * WIP: Google auth redirect fix * WIP: Fix Google OAuth2 * WIP: Fix idToken parsing * WIP: Fix fetching public profile * Working Google login * Improve logs * Fix Google login * Handle prod URL * Implement logout
- Loading branch information
1 parent
13f722f
commit 6348daf
Showing
31 changed files
with
363 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
class AppConfiguration { | ||
val fakesEnabled = true | ||
val fakesEnabled = false | ||
val useLocalServer = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import domain.SessionManager | ||
import ivy.model.auth.SessionToken | ||
import navigation.Navigation | ||
import ui.screen.home.HomeScreen | ||
|
||
class AppViewModel( | ||
private val sessionManager: SessionManager, | ||
private val platform: Platform, | ||
private val navigation: Navigation, | ||
) { | ||
|
||
@Composable | ||
fun Init() { | ||
LaunchedEffect(Unit) { | ||
redirectLoggedUsers() | ||
} | ||
} | ||
|
||
private suspend fun redirectLoggedUsers() { | ||
if (sessionManager.getSession() != null) { | ||
// already logged | ||
navigation.replaceWith(HomeScreen()) | ||
return | ||
} | ||
|
||
val sessionTokenParam = platform.getUrlParam(IvyConstants.SessionTokenParam) | ||
if (sessionTokenParam != null) { | ||
sessionManager.authenticate(SessionToken(sessionTokenParam)) | ||
navigation.replaceWith(HomeScreen()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
composeApp/src/commonMain/kotlin/data/storage/LocalStorage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package data.storage | ||
|
||
interface LocalStorage { | ||
suspend fun putString(key: String, value: String) | ||
suspend fun getString(key: String): String? | ||
suspend fun putInt(key: String, value: Int) | ||
suspend fun getInt(key: String): Int? | ||
suspend fun putDouble(key: String, value: Double) | ||
suspend fun getDouble(key: String): Double? | ||
suspend fun putBoolean(key: String, value: Boolean) | ||
suspend fun getBoolean(key: String): Boolean? | ||
|
||
suspend fun remove(key: String) | ||
suspend fun removeAll() | ||
suspend fun keys(): List<String> | ||
} | ||
|
||
expect fun localStorage(): LocalStorage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package domain | ||
|
||
import data.storage.LocalStorage | ||
import ivy.model.auth.SessionToken | ||
|
||
class SessionManager( | ||
private val localStorage: LocalStorage, | ||
) { | ||
private var sessionToken: SessionToken? = null | ||
|
||
suspend fun authenticate(token: SessionToken) { | ||
localStorage.putString(SESSION_TOKEN_KEY, token.value) | ||
sessionToken = token | ||
} | ||
|
||
suspend fun getSession(): SessionToken? { | ||
return sessionToken ?: localStorage.getString(SESSION_TOKEN_KEY) | ||
?.let(::SessionToken) | ||
?.also { | ||
sessionToken = it | ||
} | ||
} | ||
|
||
suspend fun logout() { | ||
sessionToken = null | ||
localStorage.remove(SESSION_TOKEN_KEY) | ||
} | ||
|
||
companion object { | ||
const val SESSION_TOKEN_KEY = "sessionToken" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
composeApp/src/desktopMain/kotlin/data/storage/LocalStorage.desktop.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package data.storage | ||
|
||
actual fun localStorage(): LocalStorage { | ||
TODO("Not yet implemented") | ||
} |
Oops, something went wrong.