crates/monetize-ui-server/src/app.rs
//! What every handler shares.
use std::path::PathBuf;
use std::sync::Arc;
use crate::auth::Webauthn;
use crate::grpc::Monetize;
use crate::sse::EventHub;
pub struct App {
/// `None` when passkey login is not configured: the `/auth/passkey/*`
/// surface is off and the console is open on loopback.
pub webauthn: Option<Arc<Webauthn>>,
/// The break-glass bearer, used once to enroll the first admin passkey and
/// refused from then on (see [`Webauthn::admin_token_usable`]).
pub admin_token: Option<String>,
pub monetize: Monetize,
/// ★ UW-3: the same monetize, called with the OPERATOR bearer — only the money fixes
/// (`crate::money`) use it. `None`: this console cannot refund or settle.
pub operator: Option<Monetize>,
pub events: EventHub,
/// Where trunk's `dist/` lives. `None` serves the API only.
pub ui_dir: Option<PathBuf>,
}
pub type AppState = Arc<App>;
impl App {
pub fn passkey_enabled(&self) -> bool {
self.webauthn.is_some()
}
/// True when nothing guards the console at all (the `trunk serve` posture).
pub fn is_open(&self) -> bool {
!self.passkey_enabled() && self.admin_token.is_none()
}
}