use leptos::*; use crate::prelude::*; #[component] pub fn LoginBox( token_tx: WriteSignal>, userid_tx: WriteSignal>, ) -> impl IntoView { let auth = use_context::().expect("missing auth context"); let username_ref: NodeRef = create_node_ref(); let password_ref: NodeRef = create_node_ref(); let feeds = use_context::().expect("missing feeds context"); view! {
() .await else { if let Some(rf) = password_ref.get() { rf.set_value("") }; return }; logging::log!("logged in until {}", auth_response.expires); // update our username and token cookies let username = auth_response.user.split('/').last().unwrap_or_default().to_string(); userid_tx.set(Some(auth_response.user)); token_tx.set(Some(auth_response.token)); // reset home feed and point it to our user's inbox feeds.home.reset(Some(format!("{URL_BASE}/actors/{username}/inbox/page"))); feeds.home.spawn_more(auth); feeds.notifications.reset(Some(format!("{URL_BASE}/actors/{username}/notifications/page"))); feeds.notifications.spawn_more(auth); // reset server feed: there may be more content now that we're authed feeds.global.reset(Some(format!("{URL_BASE}/inbox/page"))); feeds.global.spawn_more(auth); feeds.server.reset(Some(format!("{URL_BASE}/outbox/page"))); feeds.server.spawn_more(auth); }); } >
} } #[derive(Debug, serde::Serialize)] struct LoginForm { email: String, password: String, } #[derive(Debug, Clone, serde::Deserialize)] pub struct AuthResponse { pub token: String, pub user: String, pub expires: chrono::DateTime, }