Hildebrandt Tobias
06/04/2024, 11:36 AMval MainLoader = LoaderFunction<Any?> { args, handler ->
val currentPath = window.location.pathname
val kcRedirect = encodeURIComponent("${environment.FRONTEND_URL}/login/callback?redirect=$currentPath")
if (currentPath != basePathWith("/login") && currentPath != basePathWith("/login/callback")) {
val state = AuthStore.getAuthState()
if (state == AuthState.NONE || state == AuthState.EXPIRED) {
println("REDIRECT")
PromiseResult(redirect("$kcLoginUrl$kcRedirect", args))
}
}
PromiseResult(args)
}
The AuthStore
is a singleton that only looks into the session storage for a token and returns if it's still valid.
The console prints the REDIRECT
but no redirect is happening.
When I strip the function down to PromiseResult(redirect("<https://google.de>", args))
it redirects to google.Hildebrandt Tobias
06/04/2024, 12:41 PMval MainLoader = LoaderFunction<Any?> { args, handler ->
val currentPath = window.location.pathname
val kcRedirect = encodeURIComponent("${environment.FRONTEND_URL}/login/callback?redirect=$currentPath")
if (currentPath != basePathWith("/login") && currentPath != basePathWith("/login/callback")) {
when (AuthStore.getAuthState()) {
AuthState.NONE, AuthState.EXPIRED -> {
PromiseResult(redirect("$kcLoginUrl$kcRedirect", args))
}
else ->
PromiseResult(args)
}
} else
PromiseResult(args)
}
Even though the code path leads to the PromiseResult(redirect)
the other PromisResult
intervened it seems.
I only use one PromiseResult
now and it works again:
val MainLoader = LoaderFunction<Any?> { args, handler ->
val currentPath = window.location.pathname
val kcRedirect = encodeURIComponent("${environment.FRONTEND_URL}/login/callback?redirect=$currentPath")
val redirect = when (AuthStore.getAuthState()) {
AuthState.NONE, AuthState.EXPIRED -> {
if (currentPath != basePathWith("/login") && currentPath != basePathWith("/login/callback")) {
redirect("$kcLoginUrl$kcRedirect", args)
} else null
}
else -> null
}
PromiseResult(redirect ?: args)
}
Artem Kobzar
06/04/2024, 1:34 PMturansky
06/04/2024, 1:52 PMHildebrandt Tobias
06/04/2024, 2:46 PMPromiseResult
solved my Problem.
Still weird behavior though.turansky
06/04/2024, 2:54 PMelse
turansky
06/04/2024, 2:55 PMPromiseResult(args)
(last expression) - it's standard Kotlin function behaviourHildebrandt Tobias
06/04/2024, 3:02 PMHildebrandt Tobias
06/04/2024, 3:04 PMturansky
06/04/2024, 3:04 PMval MainLoader = LoaderFunction<Any?> { args, _ ->
MainLoaderImpl(args)
}
private fun MainLoaderImpl(args): PromiseResult<Any?> {
val currentPath = window.location.pathname
val kcRedirect = encodeURIComponent("${environment.FRONTEND_URL}/login/callback?redirect=$currentPath")
if (currentPath != basePathWith("/login") && currentPath != basePathWith("/login/callback")) {
val state = AuthStore.getAuthState()
if (state == AuthState.NONE || state == AuthState.EXPIRED) {
println("REDIRECT")
return PromiseResult(redirect("$kcLoginUrl$kcRedirect", args))
}
}
return PromiseResult(args)
}
turansky
06/04/2024, 3:06 PMreturn
it's much simplerHildebrandt Tobias
06/04/2024, 3:06 PMturansky
06/04/2024, 3:07 PMHildebrandt Tobias
06/04/2024, 3:12 PMHildebrandt Tobias
06/04/2024, 3:13 PMHildebrandt Tobias
06/04/2024, 3:13 PMturansky
06/04/2024, 3:18 PMwindow.location.pathname
call is unsafe/validturansky
06/04/2024, 3:19 PMargs
you have request
and context
- probably you can use itHildebrandt Tobias
06/04/2024, 3:20 PM