forked from alemi/upub
fix(web): only refresh if logged in
This commit is contained in:
parent
dfbac324f5
commit
399fdecee7
1 changed files with 20 additions and 18 deletions
|
@ -12,10 +12,11 @@ pub fn App() -> impl IntoView {
|
||||||
let (userid, set_userid) = use_cookie::<String, FromToStringCodec>("user_id");
|
let (userid, set_userid) = use_cookie::<String, FromToStringCodec>("user_id");
|
||||||
let (config, set_config, _) = use_local_storage::<crate::Config, JsonCodec>("config");
|
let (config, set_config, _) = use_local_storage::<crate::Config, JsonCodec>("config");
|
||||||
|
|
||||||
|
if let Some(tok) = token.get_untracked() {
|
||||||
spawn_local(async move {
|
spawn_local(async move {
|
||||||
match reqwest::Client::new()
|
match reqwest::Client::new()
|
||||||
.request(Method::PATCH, format!("{URL_BASE}/auth"))
|
.request(Method::PATCH, format!("{URL_BASE}/auth"))
|
||||||
.json(&serde_json::json!({"token": token.get().unwrap_or_default()}))
|
.json(&serde_json::json!({"token": tok}))
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
@ -31,7 +32,8 @@ pub fn App() -> impl IntoView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
};
|
||||||
|
|
||||||
let auth = Auth { token, userid };
|
let auth = Auth { token, userid };
|
||||||
provide_context(auth);
|
provide_context(auth);
|
||||||
|
|
Loading…
Reference in a new issue