Smeltery
Get started

Alloy

v0.1

Shared props

Alloy::share(f) adds props to every page, under the page's own (a page prop with the same key wins); the page's sharedProps lists their keys. f gets a SharedCtx with app(), session(), auth(), headers(), uri() and method(). The kits share the signed-in user through an allow-list, never the model:

rust
use smeltery::alloy::{Props, SharedCtx};
use app::models::User;

/// The signed-in user as pages see it (`usePage().props.auth.user`).
#[derive(serde::Serialize)]
pub struct SharedUser {
    pub id: i64,
    pub name: String,
    pub email: String,
}

pub async fn shared(ctx: SharedCtx) -> smeltery::Result<Props> {
    let user = ctx.auth().user::<User>().await?.map(|u| SharedUser {
        id: u.id,
        name: u.name,
        email: u.email,
    });
    Ok(Props::new()
        .with("app", smeltery::json!({ "name": ctx.app().settings().name }))
        .with("auth", smeltery::json!({ "user": user })))
}

↑↓ moveEnter openEsc close