// src/state/pages/auth.rs use canvas::{DataProvider, AppMode}; /// Strongly typed user roles #[derive(Debug, Clone, PartialEq, Eq)] pub enum UserRole { Admin, Moderator, Accountant, Viewer, Unknown(String), // fallback for unexpected roles } impl UserRole { pub fn from_str(s: &str) -> Self { match s.trim().to_lowercase().as_str() { "admin" => UserRole::Admin, "moderator" => UserRole::Moderator, "accountant" => UserRole::Accountant, "viewer" => UserRole::Viewer, other => UserRole::Unknown(other.to_string()), } } pub fn as_str(&self) -> &str { match self { UserRole::Admin => "admin", UserRole::Moderator => "moderator", UserRole::Accountant => "accountant", UserRole::Viewer => "viewer", UserRole::Unknown(s) => s.as_str(), } } } /// Represents the authenticated session state #[derive(Default)] pub struct AuthState { pub auth_token: Option, pub user_id: Option, pub role: Option, pub decoded_username: Option, } impl AuthState { pub fn new() -> Self { Self::default() } }