lpotthast / leptos-keycloak-auth

Secure Leptos applications using Keycloak
Apache License 2.0
6 stars 1 forks source link

Problems integrating into leptos-axum project #2

Open cmdln opened 4 days ago

cmdln commented 4 days ago

I added the crate and tried to follow the README. I had to make some changes to the code to get cargo leptos build to work.

thread 'main' panicked at /home/cmdln/.cargo/registry/src/index.crates.io-6f17d22bba15001f/js-sys-0.3.70/src/lib.rs:6035:9:
cannot call wasm-bindgen imported functions on non-wasm targets
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at /rustc/6c6d210089e4589afee37271862b9f88ba1d7755/library/std/src/thread/local.rs:260:26:
cannot access a Thread Local Storage value during or after destruction: AccessError
fatal runtime error: thread local panicked on drop

I have a branch in my repo on my own forge that reproduces this error: https://git.cmdln.net/cmdln/watch/src/branch/add-keycloak.

I am using leptos 0.6 with nightly. I tried disabling nightly and still get the error. FWIW, I also tried leptos-oidc with this project and ran into different errors. I am exploring using Keycloak either way so don't mind that your crate has that specific dependency.

cmdln commented 3 days ago

I resolved this problem with cargo add leptos-use then adding lepto-use to the hydrate feature in my project.

I now can get login to work. After login, the redirect has the session state parameter making me wonder if I am missing something in my config. If I reload the page, the app acts as if I am not authenticated and the sign in url used in my unauthenticated fallback reverts to being empty.

I see you wrote an axum crate as well, I am going to try adding that since it seems like it could handle the missing piece, processing the redirect for the oidc callback.