Skip to main content

SessionManager

Struct SessionManager 

Source
pub struct SessionManager<DB: DatabaseAdapter> { /* private fields */ }
Expand description

Session manager handles session creation, validation, and cleanup

Implementations§

Source§

impl<DB: DatabaseAdapter> SessionManager<DB>

Source

pub fn new(config: Arc<AuthConfig>, database: Arc<DB>) -> Self

Source

pub async fn create_session( &self, user: &impl AuthUser, ip_address: Option<String>, user_agent: Option<String>, ) -> AuthResult<DB::Session>

Create a new session for a user

Source

pub async fn get_session(&self, token: &str) -> AuthResult<Option<DB::Session>>

Get session by token

Source

pub async fn delete_session(&self, token: &str) -> AuthResult<()>

Delete a session

Source

pub async fn delete_user_sessions(&self, user_id: &str) -> AuthResult<()>

Delete all sessions for a user

Source

pub async fn list_user_sessions( &self, user_id: &str, ) -> AuthResult<Vec<DB::Session>>

Get all active sessions for a user

Source

pub async fn revoke_session(&self, token: &str) -> AuthResult<bool>

Revoke a specific session by token

Source

pub async fn revoke_all_user_sessions(&self, user_id: &str) -> AuthResult<usize>

Revoke all sessions for a user

Source

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

Source

pub async fn cleanup_expired_sessions(&self) -> AuthResult<usize>

Cleanup expired sessions

Source

pub fn validate_token_format(&self, token: &str) -> bool

Validate session token format

Source

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<DB> Freeze for SessionManager<DB>

§

impl<DB> !RefUnwindSafe for SessionManager<DB>

§

impl<DB> Send for SessionManager<DB>

§

impl<DB> Sync for SessionManager<DB>

§

impl<DB> Unpin for SessionManager<DB>

§

impl<DB> !UnwindSafe for SessionManager<DB>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,