Skip to content

Commit 009f353

Browse files
committed
Add role visiblity
1 parent 95730ab commit 009f353

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

starter/src/frontend/src/components/Sidebar.astro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
</li>
5555
</ul>
5656
</div>
57+
<Fragment set:html={'{% if role == "admin" %}'} />
5758
<div>
5859
<ul class="flex flex-col flex-1 gap-1 py-3">
5960
<li class="px-3">
@@ -84,6 +85,7 @@
8485
</li>
8586
</ul>
8687
</div>
88+
<Fragment set:html={"{% endif %}"} />
8789
</nav>
8890

8991
<footer class="p-3 border-t border-secondary-200">

starter/src/services/index.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use crate::{AppData, AuthUser, Data, Responder, get};
1+
use crate::{AppData, AuthUser, Data, Responder, get, json};
22

33
#[get("/")]
4-
pub async fn index(data: Data<AppData>, _user: AuthUser) -> impl Responder {
5-
data.render("index").await
4+
pub async fn index(data: Data<AppData>, user: AuthUser) -> impl Responder {
5+
data.render_tpl("index", &json!({ "role": user.claims.role.to_string() }))
6+
.await
67
}

starter/src/services/users.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,17 @@ pub async fn get(data: web::Data<AppData>, _user: AdminUser) -> AppResult {
6161
actions: vec![],
6262
};
6363

64-
Ok(data.render_tpl("users", &table).await)
64+
Ok(data
65+
.render_tpl(
66+
"users",
67+
&crate::json!({
68+
"headers": table.headers,
69+
"rows": table.rows,
70+
"actions": table.actions,
71+
"role": "admin"
72+
}),
73+
)
74+
.await)
6575
}
6676

6777
#[get("/users/{id}")]
@@ -75,7 +85,16 @@ pub async fn get_user(
7585
.fetch_one(&data.db)
7686
.await?;
7787

78-
Ok(data.render_tpl("user", &user_data).await)
88+
Ok(data
89+
.render_tpl(
90+
"user",
91+
&crate::json!({
92+
"id": user_data.id,
93+
"email": user_data.email,
94+
"role": "admin"
95+
}),
96+
)
97+
.await)
7998
}
8099

81100
#[derive(Deserialize)]

0 commit comments

Comments
 (0)