pub struct SessionManager { /* private fields */ }
Expand description
Session manager for handling session lifecycle
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn new(config: SessionConfig, storage: Arc<dyn SessionStorage>) -> Self
pub fn new(config: SessionConfig, storage: Arc<dyn SessionStorage>) -> Self
Create a new session manager
Sourcepub fn with_default_config() -> Self
pub fn with_default_config() -> Self
Create with default configuration and memory storage
Sourcepub async fn create_session(
&self,
user_id: String,
auth_context: AuthContext,
duration: Option<Duration>,
client_ip: Option<String>,
user_agent: Option<String>,
) -> Result<(Session, Option<String>), SessionError>
pub async fn create_session( &self, user_id: String, auth_context: AuthContext, duration: Option<Duration>, client_ip: Option<String>, user_agent: Option<String>, ) -> Result<(Session, Option<String>), SessionError>
Create a new session for a user
Sourcepub async fn get_session(
&self,
session_id: &str,
) -> Result<Session, SessionError>
pub async fn get_session( &self, session_id: &str, ) -> Result<Session, SessionError>
Get a session by ID
Sourcepub async fn validate_session(
&self,
session_id: &str,
) -> Result<Session, SessionError>
pub async fn validate_session( &self, session_id: &str, ) -> Result<Session, SessionError>
Validate and refresh a session
Sourcepub async fn validate_jwt_token(
&self,
token: &str,
) -> Result<AuthContext, SessionError>
pub async fn validate_jwt_token( &self, token: &str, ) -> Result<AuthContext, SessionError>
Validate a JWT token and return session
Sourcepub async fn refresh_session(
&self,
session_id: &str,
refresh_token: &str,
) -> Result<(Session, Option<String>), SessionError>
pub async fn refresh_session( &self, session_id: &str, refresh_token: &str, ) -> Result<(Session, Option<String>), SessionError>
Refresh a session using refresh token
Sourcepub async fn terminate_session(
&self,
session_id: &str,
) -> Result<(), SessionError>
pub async fn terminate_session( &self, session_id: &str, ) -> Result<(), SessionError>
Terminate a session
Sourcepub async fn terminate_user_sessions(
&self,
user_id: &str,
) -> Result<u64, SessionError>
pub async fn terminate_user_sessions( &self, user_id: &str, ) -> Result<u64, SessionError>
Terminate all sessions for a user
Sourcepub async fn get_user_sessions(
&self,
user_id: &str,
) -> Result<Vec<Session>, SessionError>
pub async fn get_user_sessions( &self, user_id: &str, ) -> Result<Vec<Session>, SessionError>
Get all active sessions for a user
Sourcepub async fn cleanup_expired_sessions(&self) -> Result<u64, SessionError>
pub async fn cleanup_expired_sessions(&self) -> Result<u64, SessionError>
Clean up expired sessions
Sourcepub async fn start_cleanup_task(&self) -> JoinHandle<()>
pub async fn start_cleanup_task(&self) -> JoinHandle<()>
Start background cleanup task
Sourcepub async fn get_session_stats(&self) -> Result<SessionStats, SessionError>
pub async fn get_session_stats(&self) -> Result<SessionStats, SessionError>
Get session statistics
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