Trait axum_login::AuthUser

source ·
pub trait AuthUser: Debug + Clone + Send + Sync {
    type Id: Debug + Display + Clone + Send + Sync + Serialize + for<'de> Deserialize<'de>;

    // Required methods
    fn id(&self) -> Self::Id;
    fn session_auth_hash(&self) -> &[u8] ⓘ;
}
Expand description

A user which can be identified, authenticated, and authorized.

Examples

use axum_login::AuthUser;

#[derive(Debug, Clone)]
struct User {
    id: i64,
    pw_hash: Vec<u8>,
}

impl AuthUser for User {
    type Id = i64;

    fn id(&self) -> Self::Id {
        self.id
    }

    fn session_auth_hash(&self) -> &[u8] {
        &self.pw_hash
    }
}

Required Associated Types§

source

type Id: Debug + Display + Clone + Send + Sync + Serialize + for<'de> Deserialize<'de>

An identifying feature of the user.

Required Methods§

source

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

Returns some identifying feature of the user.

source

fn session_auth_hash(&self) -> &[u8] ⓘ

Returns a hash that’s used by the session to verify the session is valid.

For example, if users have passwords, this method might return a cryptographically secure hash of that password.

Object Safety§

This trait is not object safe.

Implementors§