I am building a full-stack Leptos/Axum – SSR/Hydrate web app with JWT authentication…
The problem is that, once I have the JWT token in the browser’s local storage, the protected route redirects to the Login page regardless of the JWT presence (the user exists)…
This happens during the initial page load only.
Clicking on the protected page link (HomePage) will navigate to the page correctly…
Here is a slice of the routes configuration (in the app.rs file):
...
<Route path="/" view=move || {
view! {
<Show when=move || { global_state.current_user.get().is_none()}>
<Redirect path=LOGIN_URL/>
</Show>
<Outlet/>
}
}
>
<Route path="/" view=HomePage/>
</Route>
...
Here is a slice of the logic (in the app.rs file):
...
let global_state = use_context::<GlobalState>().unwrap();
create_effect(move |_| {
let current_user = AuthService::get_current_user();
if current_user.user_name.is_empty() {
global_state.current_user.set(None);
} else {
global_state.current_user.set(Some(CurrentUser {
user_name: create_rw_signal(current_user.user_name.clone()),
}));
}
});
...
What can be wrong here?