DataProvider

Trait DataProvider 

Source
pub trait DataProvider: Clone {
    type AccountType: Account;

    // Required methods
    fn insert_account<'life0, 'async_trait>(
        &'life0 self,
        account: Self::AccountType,
        password_hash: String,
    ) -> Pin<Box<dyn Future<Output = ResponseResult<Self::AccountType>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn fetch_account<'life0, 'life1, 'async_trait>(
        &'life0 self,
        email: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = ResponseResult<Option<(Self::AccountType, String)>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

A struct that implements this trait provides the functions that Actix+Auth needs to interact with your database (or flatfile, volatile storage in ram, whatever you want) to implement authentication. Although it is not strictly required to work at small scale, it is strongly recommended that the email of each account be able to be looked up quickly in a case-insensitive manner. With a SQL database, this can be accomplished by adding an index on the lowercase of the email. The email is also the primary key. Note that when this struct is cloned it should refer to the same datastore. This struct is cloned like a database pool is in normal Actix.

Required Associated Types§

Required Methods§

Source

fn insert_account<'life0, 'async_trait>( &'life0 self, account: Self::AccountType, password_hash: String, ) -> Pin<Box<dyn Future<Output = ResponseResult<Self::AccountType>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Adds a new account to the database, then returns that account back. You may need to clone the account when implementing this function. If another account exists with this email, then the function should return some sort of error.

Source

fn fetch_account<'life0, 'life1, 'async_trait>( &'life0 self, email: &'life1 str, ) -> Pin<Box<dyn Future<Output = ResponseResult<Option<(Self::AccountType, String)>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetches the account with the given email from the database, case-insensitively. Note that a lowercase email should be passed to this function, but the matching email as stored in the database may be in any case.

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§