pub struct SessionManager { /* private fields */ }Expand description
Session manager handles session creation, validation, and cleanup
Implementations§
Source§impl SessionManager
impl SessionManager
pub fn new(config: Arc<AuthConfig>, database: Arc<dyn DatabaseAdapter>) -> Self
Sourcepub async fn create_session(
&self,
user: &User,
ip_address: Option<String>,
user_agent: Option<String>,
) -> AuthResult<Session>
pub async fn create_session( &self, user: &User, ip_address: Option<String>, user_agent: Option<String>, ) -> AuthResult<Session>
Create a new session for a user
Sourcepub async fn get_session(&self, token: &str) -> AuthResult<Option<Session>>
pub async fn get_session(&self, token: &str) -> AuthResult<Option<Session>>
Get session by token
Sourcepub async fn delete_session(&self, token: &str) -> AuthResult<()>
pub async fn delete_session(&self, token: &str) -> AuthResult<()>
Delete a session
Sourcepub async fn delete_user_sessions(&self, user_id: &str) -> AuthResult<()>
pub async fn delete_user_sessions(&self, user_id: &str) -> AuthResult<()>
Delete all sessions for a user
Sourcepub async fn list_user_sessions(
&self,
user_id: &str,
) -> AuthResult<Vec<Session>>
pub async fn list_user_sessions( &self, user_id: &str, ) -> AuthResult<Vec<Session>>
Get all active sessions for a user
Sourcepub async fn revoke_session(&self, token: &str) -> AuthResult<bool>
pub async fn revoke_session(&self, token: &str) -> AuthResult<bool>
Revoke a specific session by token
Sourcepub async fn revoke_all_user_sessions(&self, user_id: &str) -> AuthResult<usize>
pub async fn revoke_all_user_sessions(&self, user_id: &str) -> AuthResult<usize>
Revoke all sessions for a user
Sourcepub async fn revoke_other_user_sessions(
&self,
user_id: &str,
current_token: &str,
) -> AuthResult<usize>
pub async fn revoke_other_user_sessions( &self, user_id: &str, current_token: &str, ) -> AuthResult<usize>
Revoke all sessions for a user except the current one
Sourcepub async fn cleanup_expired_sessions(&self) -> AuthResult<usize>
pub async fn cleanup_expired_sessions(&self) -> AuthResult<usize>
Cleanup expired sessions
Sourcepub fn validate_token_format(&self, token: &str) -> bool
pub fn validate_token_format(&self, token: &str) -> bool
Validate session token format
Sourcepub fn extract_session_token(&self, req: &AuthRequest) -> Option<String>
pub fn extract_session_token(&self, req: &AuthRequest) -> Option<String>
Extract session token from a request.
Tries Bearer token from Authorization header first, then falls back to parsing the configured cookie from the Cookie header.
Auto Trait Implementations§
impl Freeze for SessionManager
impl !RefUnwindSafe for SessionManager
impl Send for SessionManager
impl Sync for SessionManager
impl Unpin for SessionManager
impl !UnwindSafe for SessionManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more