|
I am working on a login component in a fullstack app, that when an already logged in user loads, it will redirect to the main page. However, I get a perplexing error in my browser console: My component is use crate::components::button::Button;
use crate::components::input::Input;
use crate::components::label::Label;
use crate::get_login_status;
use crate::login;
use crate::Route;
use dioxus::prelude::*;
#[component]
pub fn Login() -> Element {
let mut username = use_signal(|| String::new());
let mut password = use_signal(|| String::new());
// let mut response = use_signal(|| String::new());
let status = use_server_future(|| get_login_status())?.unwrap().unwrap();
use_effect(move || {
if status {
navigator().replace(Route::Home {});
}
});
rsx! {
div { id: "title",
h1 { "Log ind" }
}
div { width: "300px", gap: ".5rem",
Label { html_for: "username", "Brugernavn" }
Input {
id: "username",
oninput: move |event: FormEvent| async move {
username.set(event.value());
},
}
Label { html_for: "password", "Kode" }
Input {
oninput: move |event: FormEvent| {
password.set(event.value());
},
id: "password",
r#type: "password",
}
// {response}
}
Button {
onclick: move |_| async move {
match login(username(), password()).await {
Ok(_) => {
// response.set("Login successful".to_string());
navigator().replace(Route::Home {});
}
Err(_) => println!("login error"),
}
},
"Log ind"
}
}
}where the server function is given by #[post("/api/user/status", auth: aux::Session)]
pub async fn get_login_status() -> Result<bool, ServerFnError> {
let status = auth.is_authenticated();
Ok(status)
}any help would be greatly appreciated! |
Answered by
madsmh
Aug 9, 2026
Replies: 2 comments
|
I don't see anything wrong with that component on its own. You could try #5357 to see exactly where the mismatch is between the server and client |
0 replies
|
I go it to work by replacing in Cargo.toml, with |
0 replies
Answer selected by
madsmh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I go it to work by replacing
in Cargo.toml, with