diff --git a/web/Cargo.toml b/web/Cargo.toml index e207bff1..5f097086 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -27,3 +27,4 @@ apb = { path = "../apb", features = ["unstructured"] } futures = "0.3.30" dissolve = "0.2" # TODO strip html without this crate lazy_static = "1.4" +chrono = { version = "0.4", features = ["serde"] } diff --git a/web/src/lib.rs b/web/src/lib.rs index 6d3acc2a..457364aa 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -17,7 +17,7 @@ struct LoginForm { fn web_uri(kind: &str, url: &str) -> String { if url.starts_with(URL_BASE) { - format!("/web/{kind}/{}", url.split('/').last().unwrap_or_default().to_string()) + format!("/web/{kind}/{}", url.split('/').last().unwrap_or_default()) } else { format!("/web/{kind}/+{}", url.replace("https://", "").replace('/', "@")) } @@ -31,17 +31,25 @@ fn api_uri(kind: &str, url: &str) -> String { } } +#[derive(Debug, serde::Deserialize)] +struct AuthSuccess { + token: String, + user: String, + expires: chrono::DateTime, +} + #[component] pub fn LoginBox( rx: Signal>, tx: WriteSignal>, ) -> impl IntoView { + let (username, username_set) = create_signal("".to_string()); let username_ref: NodeRef = create_node_ref(); let password_ref: NodeRef = create_node_ref(); view! {
- "Hello "test + "Hello "{move || username.get()} @@ -59,9 +67,11 @@ pub fn LoginBox( .json(&LoginForm { email, password }) .send() .await.unwrap() - .json::() + .json::() .await.unwrap(); - tx.set(Some(auth)); + tx.set(Some(auth.token)); + username_set.set(auth.user); + console_log(&format!("logged in until {}", auth.expires)); }); } />