Skip to content

Commit

Permalink
Fix Google login
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Nov 30, 2024
1 parent 177de83 commit 61aa042
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 35 deletions.
4 changes: 2 additions & 2 deletions composeApp/src/commonMain/kotlin/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class AppViewModel(
@Composable
fun Init() {
LaunchedEffect(Unit) {
initialize()
redirectLoggedUsers()
}
}

private suspend fun initialize() {
private suspend fun redirectLoggedUsers() {
if (sessionManager.getSession() != null) {
// already logged
navigation.replaceWith(HomeScreen())
Expand Down
2 changes: 0 additions & 2 deletions composeApp/src/commonMain/kotlin/navigation/Navigation.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package navigation

import Platform
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
Expand All @@ -9,7 +8,6 @@ import ui.screen.NotFoundPage

class Navigation(
private val systemNavigation: SystemNavigation,
private val platform: Platform,
) {
@Composable
fun NavHost() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ fun HomeContent(
onEvent: (HomeViewEvent) -> Unit
) {
LearnScaffold(
backButton = BackButton(
onBackClick = {
onEvent(HomeViewEvent.OnBackClick)
}
),
backButton = null,
title = "Learn",
actions = {
// TODO - update button
Expand Down
48 changes: 24 additions & 24 deletions composeApp/src/jsMain/kotlin/data/storage/LocalStorage.js.kt
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
package data.storage

import kotlinx.browser.window
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.w3c.dom.get
import org.w3c.dom.set

class WebLocalLocalStorage : LocalStorage {
override suspend fun putString(
key: String,
value: String
) = withContext(Dispatchers.Default) {
window.localStorage[key] = value
) {
storage.setItem(key, value)
}

override suspend fun getString(key: String): String? = withContext(Dispatchers.Default) {
window.localStorage[key]
override suspend fun getString(key: String): String? {
return storage.getItem(key)
}

override suspend fun putInt(
key: String,
value: Int
) = withContext(Dispatchers.Default) {
window.localStorage[key] = value.toString()
) {
storage.setItem(key, value.toString())
}

override suspend fun getInt(key: String): Int? = withContext(Dispatchers.Default) {
window.localStorage[key]?.toIntOrNull()
override suspend fun getInt(key: String): Int? {
return storage.getItem(key)?.toIntOrNull()
}


override suspend fun putDouble(
key: String,
value: Double
) = withContext(Dispatchers.Default) {
window.localStorage[key] = value.toString()
) {
storage.setItem(key, value.toString())
}

override suspend fun getDouble(key: String): Double? = withContext(Dispatchers.Default) {
window.localStorage[key]?.toDoubleOrNull()
override suspend fun getDouble(key: String): Double? {
return storage.getItem(key)?.toDoubleOrNull()
}

override suspend fun putBoolean(
key: String,
value: Boolean
) = withContext(Dispatchers.Default) {
window.localStorage[key] = value.toString()
) {
storage.setItem(key, value.toString())
}

override suspend fun getBoolean(key: String): Boolean? = withContext(Dispatchers.Default) {
window.localStorage[key]?.toBooleanStrictOrNull()
override suspend fun getBoolean(key: String): Boolean? {
return storage.getItem(key)?.toBooleanStrictOrNull()
}

override suspend fun remove(key: String) {
window.localStorage.removeItem(key)
storage.removeItem(key)
}

override suspend fun removeAll() {
window.localStorage.clear()
storage.clear()
}

override suspend fun keys(): List<String> {
return (0..window.localStorage.length)
return (0..storage.length)
.mapNotNull {
window.localStorage.key(it)
storage.key(it)
}
}

private val storage
get() = window.localStorage
}

actual fun localStorage(): LocalStorage = WebLocalLocalStorage()
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class WebSystemNavigation : SystemNavigation {

override fun replaceWith(screen: Screen) {
window.history.replaceState(js("({})"), "", screen.toFullPath())
emitCurrentRoute()
}

private fun Screen.toFullPath(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GoogleAuthenticationApi(
val auth = authService.authenticate(googleAuthCode)
.mapLeft(ServerError::Unknown)
.bind()
val sessionToken = auth.session.token
val sessionToken = auth.session.token.value
val frontEndUrl = if (serverMode.devMode) {
IvyUrls.devFrontEnd
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GoogleOAuthUseCase(
names = userInfoResponse.name,
profilePictureUrl = userInfoResponse.picture,
).also {
logger.info("Google verification succeeded for $it")
logger.debug("Google verification succeeded for {}", it)
}
}

Expand Down

0 comments on commit 61aa042

Please sign in to comment.