Correctly handle shared state
This commit is contained in:
parent
183f8a75d2
commit
ede98561b5
2 changed files with 19 additions and 6 deletions
|
|
@ -170,7 +170,7 @@ pub fn FullContextRedirect<'a>(cx: Scope<'a, RedirectorProps<'a>>) -> Element {
|
|||
Ok(_) => true,
|
||||
Err(StorageError::KeyNotFound(_)) => {
|
||||
navigator.push(Route::Login);
|
||||
false
|
||||
return None;
|
||||
}
|
||||
Err(e) => unreachable!("Could not get token: {e:?}"),
|
||||
};
|
||||
|
|
@ -179,7 +179,7 @@ pub fn FullContextRedirect<'a>(cx: Scope<'a, RedirectorProps<'a>>) -> Element {
|
|||
Ok(_) => true,
|
||||
Err(StorageError::KeyNotFound(_)) => {
|
||||
navigator.push(Route::HouseholdSelection);
|
||||
false
|
||||
return None;
|
||||
}
|
||||
Err(e) => unreachable!("Could not get household: {e:?}"),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -134,7 +134,8 @@ pub fn LoginRedirect(cx: Scope) -> Element {
|
|||
let token = match LocalStorage::get::<LoginInfo>("token") {
|
||||
Ok(v) => Some(v),
|
||||
Err(StorageError::KeyNotFound(_)) => {
|
||||
return None;
|
||||
navigator.push(Route::Login);
|
||||
None
|
||||
}
|
||||
Err(e) => unreachable!("Could not get token: {e:?}"),
|
||||
};
|
||||
|
|
@ -142,16 +143,28 @@ pub fn LoginRedirect(cx: Scope) -> Element {
|
|||
use_shared_state_provider(cx, || token.clone());
|
||||
|
||||
cx.render(match token {
|
||||
Some(_) => rsx! {
|
||||
Outlet::<Route> {}
|
||||
Some(info) => rsx! {
|
||||
LoginRedirectInner {info: info},
|
||||
},
|
||||
None => {
|
||||
navigator.push(Route::Login);
|
||||
rsx! {{}}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Props, PartialEq)]
|
||||
struct LoginRedirectInnerProps {
|
||||
info: LoginInfo,
|
||||
}
|
||||
|
||||
fn LoginRedirectInner(cx: Scope<LoginRedirectInnerProps>) -> Element {
|
||||
use_shared_state_provider(cx, || cx.props.info.clone());
|
||||
|
||||
cx.render(rsx! {
|
||||
Outlet::<Route> {}
|
||||
})
|
||||
}
|
||||
|
||||
async fn do_login(username: String, password: String) -> anyhow::Result<()> {
|
||||
let rsp = gloo_net::http::Request::post(api!("login"))
|
||||
.json(&LoginRequest {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue