Skip to main content

Authenticatable

Trait Authenticatable 

Source
pub trait Authenticatable:
    Send
    + Sync
    + Sized
    + Clone
    + 'static {
    type Id: Serialize + DeserializeOwned + Send + Sync + Clone + 'static;

    // Required methods
    fn id(&self) -> Self::Id;
    fn find_by_id<'life0, 'life1, 'async_trait>(
        container: &'life0 Container,
        id: &'life1 Self::Id,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Self>, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn find_by_credentials<'life0, 'life1, 'async_trait>(
        container: &'life0 Container,
        identifier: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<(Self, String)>, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Marker trait for app-defined user models that participate in auth.

Implement (or derive via #[derive(Authenticatable)]) on the model that represents your logged-in user. The methods drive both the Auth<U> extractor (loads the current user) and attempt() (login by credentials).

Required Associated Types§

Required Methods§

Source

fn id(&self) -> Self::Id

Return this user’s ID — what gets stored in the session.

Source

fn find_by_id<'life0, 'life1, 'async_trait>( container: &'life0 Container, id: &'life1 Self::Id, ) -> Pin<Box<dyn Future<Output = Result<Option<Self>, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Look up by ID, used by the Auth<U> extractor on every request.

Source

fn find_by_credentials<'life0, 'life1, 'async_trait>( container: &'life0 Container, identifier: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<(Self, String)>, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Look up by login identifier (email, username, etc.) and return the user along with the stored password hash. Used by attempt().

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§