Skip to main content

UserProvider

Trait UserProvider 

Source
pub trait UserProvider:
    Send
    + Sync
    + 'static {
    type User: Clone + Send + Sync + 'static;

    // Required method
    fn find_by_id(
        &self,
        id: &str,
    ) -> impl Future<Output = Result<Option<Self::User>, Error>> + Send;
}
Expand description

Trait for loading a user by their session-stored ID.

Implement this on your own type (e.g., a repository struct that holds a DB pool) and register it via app.service(UserProviderService::new(your_impl)).

Required Associated Types§

Source

type User: Clone + Send + Sync + 'static

The user type returned by this provider.

Required Methods§

Source

fn find_by_id( &self, id: &str, ) -> impl Future<Output = Result<Option<Self::User>, Error>> + Send

Look up a user by their ID (as stored in the session).

Return Ok(None) if the user doesn’t exist. Return Err only for infrastructure failures (DB errors, etc.).

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§