navbar profile

This commit is contained in:
Priec
2026-06-19 13:59:31 +02:00
parent 14ae859152
commit 454d5cb349
8 changed files with 124 additions and 37 deletions

View File

@@ -46,13 +46,30 @@ pub async fn logged_in(ctx: &AppContext, jar: &CookieJar) -> bool {
}
}
/// Nav chrome flags for storefront pages, in one DB lookup: returns
/// `(logged_in_admin, logged_in_customer)`. A customer is any authenticated
/// non-admin user. Both are `false` for anonymous visitors.
pub async fn chrome(ctx: &AppContext, jar: &CookieJar) -> (bool, bool) {
/// Nav chrome for storefront pages, resolved in one DB lookup. A customer is any
/// authenticated non-admin user; `customer_name`/`customer_account_type` are set
/// only for such a customer (used by the navbar profile menu). Everything is the
/// zero value for anonymous visitors and the name/type stay `None` for admins.
#[derive(Debug, Default)]
pub struct Chrome {
pub logged_in_admin: bool,
pub logged_in_customer: bool,
pub customer_name: Option<String>,
pub customer_account_type: Option<String>,
}
pub async fn chrome(ctx: &AppContext, jar: &CookieJar) -> Chrome {
match current_user(ctx, jar).await {
Some(user) if is_admin(ctx, &user) => (true, false),
Some(_) => (false, true),
None => (false, false),
Some(user) if is_admin(ctx, &user) => Chrome {
logged_in_admin: true,
..Default::default()
},
Some(user) => Chrome {
logged_in_customer: true,
customer_name: Some(user.name),
customer_account_type: Some(user.account_type),
..Default::default()
},
None => Chrome::default(),
}
}