diff --git a/web/src/app.rs b/web/src/app.rs index 788c25ca..d09bbfa6 100644 --- a/web/src/app.rs +++ b/web/src/app.rs @@ -12,9 +12,9 @@ pub fn App() -> impl IntoView { UseCookieOptions::default() .max_age(1000 * 60 * 60 * 6) ); - let (user, set_username) = use_cookie::("username"); + let (userid, set_userid) = use_cookie::("user_id"); - let auth = Auth { token, user }; + let auth = Auth { token, userid }; provide_context(auth); let home_tl = Timeline::new(format!("{URL_BASE}/users/{}/inbox/page", auth.username())); @@ -59,7 +59,7 @@ pub fn App() -> impl IntoView {
diff --git a/web/src/auth.rs b/web/src/auth.rs index 33b4f8c7..65f1bebb 100644 --- a/web/src/auth.rs +++ b/web/src/auth.rs @@ -5,6 +5,7 @@ use crate::prelude::*; pub trait AuthToken { fn present(&self) -> bool; fn token(&self) -> String; + fn user_id(&self) -> String; fn username(&self) -> String; fn outbox(&self) -> String; } @@ -12,14 +13,14 @@ pub trait AuthToken { #[derive(Debug, Clone, Copy)] pub struct Auth { pub token: Signal>, - pub user: Signal>, + pub userid: Signal>, } #[component] pub fn LoginBox( token_tx: WriteSignal>, - username_tx: WriteSignal>, + userid_tx: WriteSignal>, home_tl: Timeline, server_tl: Timeline, ) -> impl IntoView { @@ -61,7 +62,7 @@ pub fn LoginBox( 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(); - username_tx.set(Some(username.clone())); + 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 home_tl.reset(format!("{URL_BASE}/users/{}/inbox/page", username)); @@ -107,9 +108,19 @@ impl AuthToken for Auth { fn token(&self) -> String { self.token.get().unwrap_or_default() } + + fn user_id(&self) -> String { + self.userid.get().unwrap_or_default() + } fn username(&self) -> String { - self.user.get().unwrap_or_default() + // TODO maybe cache this?? how often do i need it? + self.userid.get() + .unwrap_or_default() + .split('/') + .last() + .unwrap_or_default() + .to_string() } fn present(&self) -> bool { @@ -117,6 +128,6 @@ impl AuthToken for Auth { } fn outbox(&self) -> String { - format!("{URL_BASE}/users/{}/outbox", self.user.get().unwrap_or_default()) + format!("{URL_BASE}/users/{}/outbox", self.username()) } }