Skip to content

Commit

Permalink
More bug fixes (#64)
Browse files Browse the repository at this point in the history
* Fix Google auth redirect

* Improve back navigation for deep links
  • Loading branch information
ILIYANGERMANOV authored Dec 5, 2024
1 parent 61f37fb commit 8603037
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
5 changes: 4 additions & 1 deletion composeApp/src/commonMain/kotlin/navigation/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import ui.screen.NotFoundPage
import ui.screen.home.HomeScreen

class Navigation(
private val systemNavigation: SystemNavigation,
Expand All @@ -27,6 +28,8 @@ class Navigation(
}

fun navigateBack() {
systemNavigation.navigateBack()
if (!systemNavigation.navigateBack()) {
navigateTo(HomeScreen())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface SystemNavigation {
val currentRoute: StateFlow<Route>
fun navigateTo(screen: Screen)
fun replaceWith(screen: Screen)
fun navigateBack()
fun navigateBack(): Boolean
}

@Immutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class GoogleAuthRedirect(
private val platform: Platform,
private val sessionManager: SessionManager,
private val analytics: Analytics,
private val navigation: Navigation,
) : Redirect {
override val name = "GoogleAuth"

Expand All @@ -24,6 +25,7 @@ class GoogleAuthRedirect(
source = Source.Intro,
event = "continue_with_google"
)
navigation.replaceWith(HomeScreen())
return true
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ class WebSystemNavigation : SystemNavigation {
return "${route.path}$params"
}

override fun navigateBack() {
override fun navigateBack(): Boolean {
if (window.window.length <= 1) return false

window.history.back() // Let the browser handle back navigation
// No need to call emitCurrentRoute() here; the listener will handle it
return true
}

private fun emitCurrentRoute() {
Expand Down
12 changes: 7 additions & 5 deletions server/src/main/kotlin/ivy/learn/api/GoogleAuthenticationApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ class GoogleAuthenticationApi(
.mapLeft(ServerError::Unknown)
.bind()
val sessionToken = auth.session.token.value
val frontEndUrl = if (serverMode.devMode) {
IvyUrls.devFrontEnd
val frontendAuthRedirectUrl = if (serverMode.devMode) {
IvyUrls.devFrontendAuthRedirect
} else {
IvyUrls.frontEnd
IvyUrls.frontendAuthRedirect
}
logger.info("User '${auth.user.email}' logged on $frontEndUrl.")
call.respondRedirect("${frontEndUrl}?${IvyConstants.PARAM_SESSION_TOKEN}=$sessionToken")
logger.info("User '${auth.user.email}' logged on $frontendAuthRedirectUrl.")
call.respondRedirect(
"${frontendAuthRedirectUrl}?${IvyConstants.PARAM_SESSION_TOKEN}=$sessionToken"
)
}
}

Expand Down
4 changes: 2 additions & 2 deletions shared/src/commonMain/kotlin/ivy/IvyUrls.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package ivy
object IvyUrls {
const val tos = "https://github.com/Ivy-Apps/legal/blob/main/ivy-learn-tos.md"
const val privacy = "https://github.com/Ivy-Apps/legal/blob/main/ivy-learn-privacy.md"
const val frontEnd = "https://ivylearn.app"
const val devFrontEnd = "http://localhost:8080/"
const val frontendAuthRedirect = "https://ivylearn.app/intro"
const val devFrontendAuthRedirect = "http://localhost:8080/intro"
}

0 comments on commit 8603037

Please sign in to comment.