diff --git a/frontend/src/auth.rs b/frontend/src/auth.rs
index 9afac06..cfcd547 100644
--- a/frontend/src/auth.rs
+++ b/frontend/src/auth.rs
@@ -64,7 +64,7 @@ pub fn protected_route(props: &ProtectedRouteProps) -> Html {
});
}
- match (*auth_state) {
+ match *auth_state {
AuthState {
is_authenticated: None,
..
@@ -91,6 +91,5 @@ pub fn protected_route(props: &ProtectedRouteProps) -> Html {
props.children.clone().into()
}
}
- _ => html! {
{ "Checking permissions..." }
},
}
}
diff --git a/frontend/src/pages/basic_pages.rs b/frontend/src/pages/basic_pages.rs
index 056eb48..64e2901 100644
--- a/frontend/src/pages/basic_pages.rs
+++ b/frontend/src/pages/basic_pages.rs
@@ -1,21 +1,37 @@
+use gloo_net::http::Request;
+use wasm_bindgen_futures::spawn_local;
use yew::prelude::*;
#[component(Home)]
pub fn home_component() -> Html {
- let counter = use_state(|| 0);
- let onclick = {
- let counter = counter.clone();
- move |_| {
- let value = *counter + 1;
- counter.set(value);
- }
- };
+ let is_admin = use_state(|| None::);
- html! {
-
-
-
{ *counter }
-
+ {
+ let is_admin = is_admin.clone();
+ use_effect_with((), move |_| {
+ spawn_local(async move {
+ let response = Request::get("/api/users/current")
+ .credentials(web_sys::RequestCredentials::Include)
+ .send()
+ .await;
+
+ match response {
+ Ok(resp) if resp.status() == 200 => {
+ let user_data: serde_json::Value = resp.json().await.unwrap_or_default();
+ let admin_value = user_data["data"]["is_admin"].as_bool();
+ is_admin.set(admin_value);
+ }
+ _ => is_admin.set(Some(false)),
+ }
+ });
+ || ()
+ });
+ }
+
+ match *is_admin {
+ None => html! { { "Loading..." }
},
+ Some(true) => html! { { "You are admin" }
},
+ Some(false) => html! { { "You are a normal user" }
},
}
}
diff --git a/frontend/src/pages/user.rs b/frontend/src/pages/user.rs
index e20a925..f42abb7 100644
--- a/frontend/src/pages/user.rs
+++ b/frontend/src/pages/user.rs
@@ -1,20 +1,18 @@
-use std::net::ToSocketAddrs;
-
use gloo_net::http::Request;
use serde::{Deserialize, Serialize};
use wasm_bindgen_futures::spawn_local;
use yew::prelude::*;
use yew_router::prelude::use_navigator;
-#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
-pub struct User {
- pub id: i16,
- pub last_name: String,
- pub first_name: String,
- pub username: String,
- pub is_admin: bool,
- pub pwd: String,
-}
+// #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
+// pub struct User {
+// pub id: i16,
+// pub last_name: String,
+// pub first_name: String,
+// pub username: String,
+// pub is_admin: bool,
+// pub pwd: String,
+// }
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct UserCreateScheme {