Skip to main content

Authenticatable

Trait Authenticatable 

Source
pub trait Authenticatable:
    Send
    + Sync
    + 'static {
    // Required methods
    fn auth_identifier(&self) -> i64;
    fn as_any(&self) -> &dyn Any;

    // Provided method
    fn auth_identifier_name(&self) -> &'static str { ... }
}
Expand description

Trait for models that can be authenticated

Implement this trait on your User model to enable Auth::user().

§Example

use ferro_rs::auth::Authenticatable;
use std::any::Any;

impl Authenticatable for User {
    fn auth_identifier(&self) -> i64 {
        self.id as i64
    }

    fn as_any(&self) -> &dyn Any {
        self
    }
}

Required Methods§

Source

fn auth_identifier(&self) -> i64

Get the unique identifier for the user (typically the primary key)

Source

fn as_any(&self) -> &dyn Any

Allow downcasting to concrete type

This is used by Auth::user_as::<T>() to cast the trait object back to the concrete User type.

Provided Methods§

Source

fn auth_identifier_name(&self) -> &'static str

Get the name of the identifier column (e.g., “id”)

Override this if your user model uses a different column name.

Implementors§