pub struct UserContext {
pub user_id: String,
pub email: Option<String>,
pub name: Option<String>,
pub provider: AuthProvider,
pub session_id: Option<String>,
pub expires_at: Option<DateTime<Utc>>,
pub metadata: HashMap<String, Value>,
}Expand description
User context containing authentication and profile information
Fields§
§user_id: String§email: Option<String>§name: Option<String>§provider: AuthProvider§session_id: Option<String>§expires_at: Option<DateTime<Utc>>§metadata: HashMap<String, Value>Implementations§
Source§impl UserContext
impl UserContext
Sourcepub fn new(user_id: impl Into<String>, provider: AuthProvider) -> Self
pub fn new(user_id: impl Into<String>, provider: AuthProvider) -> Self
Create a new user context
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Check if the user is authenticated (not anonymous)
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if the session has expired
Sourcepub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
pub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
Add metadata to the user context
Sourcepub fn get_metadata(&self, key: &str) -> Option<&Value>
pub fn get_metadata(&self, key: &str) -> Option<&Value>
Get metadata value
Sourcepub fn with_email(self, email: impl Into<String>) -> Self
pub fn with_email(self, email: impl Into<String>) -> Self
Set email
Sourcepub fn with_session_id(self, session_id: impl Into<String>) -> Self
pub fn with_session_id(self, session_id: impl Into<String>) -> Self
Set session ID
Sourcepub fn with_expiration(self, expires_at: DateTime<Utc>) -> Self
pub fn with_expiration(self, expires_at: DateTime<Utc>) -> Self
Set expiration time
Sourcepub fn remove_role(&mut self, role: &str)
pub fn remove_role(&mut self, role: &str)
Remove a role from the user
Sourcepub fn has_permission(&self, permission: &str) -> bool
pub fn has_permission(&self, permission: &str) -> bool
Check if user has a specific permission
Sourcepub fn add_permission(&mut self, permission: &str)
pub fn add_permission(&mut self, permission: &str)
Add a permission to the user
Sourcepub fn remove_permission(&mut self, permission: &str)
pub fn remove_permission(&mut self, permission: &str)
Remove a permission from the user
Sourcepub fn organization_id(&self) -> Option<&str>
pub fn organization_id(&self) -> Option<&str>
Get organization/tenant ID if available
Sourcepub fn with_organization_id(self, org_id: impl Into<String>) -> Self
pub fn with_organization_id(self, org_id: impl Into<String>) -> Self
Set organization/tenant ID
Trait Implementations§
Source§impl Clone for UserContext
impl Clone for UserContext
Source§fn clone(&self) -> UserContext
fn clone(&self) -> UserContext
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for UserContext
impl Debug for UserContext
Source§impl<'de> Deserialize<'de> for UserContext
impl<'de> Deserialize<'de> for UserContext
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for UserContext
impl RefUnwindSafe for UserContext
impl Send for UserContext
impl Sync for UserContext
impl Unpin for UserContext
impl UnwindSafe for UserContext
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)