pub trait AuthDatabase {
    // Required methods
    fn get_user_by_uid(&self, uid: impl AsRef<str>) -> Option<User>;
    fn get_user_by_token(&self, token: impl AsRef<str>) -> Option<User>;
    fn get_session_by_token(&self, token: impl AsRef<str>) -> Option<Session>;
    fn update_user(&mut self, user: User) -> Result<(), AuthError>;
    fn add_user(&mut self, user: User) -> Result<(), AuthError>;
    fn remove_user(&mut self, uid: impl AsRef<str>) -> Result<(), AuthError>;
}
Expand description

Represents a database which can be used to store auth information. Must be implemented for whatever database you are using.

It is good practice to have a separate collection for authentication information and user details, so whatever collection/table you use in your implementation of this trait should ideally not be used for anything else.

Required Methods§

source

fn get_user_by_uid(&self, uid: impl AsRef<str>) -> Option<User>

Returns the user associated with the given UID, or None if not found.

source

fn get_user_by_token(&self, token: impl AsRef<str>) -> Option<User>

Returns the user who owns the given token, or None if not found.

source

fn get_session_by_token(&self, token: impl AsRef<str>) -> Option<Session>

Returns the session identified by the given token, or None if not found.

source

fn update_user(&mut self, user: User) -> Result<(), AuthError>

Update the user in the database. The user should be identified by their UID.

source

fn add_user(&mut self, user: User) -> Result<(), AuthError>

Add a user to the database.

source

fn remove_user(&mut self, uid: impl AsRef<str>) -> Result<(), AuthError>

Remove the user with the given UID from the database.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl AuthDatabase for Vec<User>

source§

fn get_user_by_uid(&self, uid: impl AsRef<str>) -> Option<User>

source§

fn get_user_by_token(&self, token: impl AsRef<str>) -> Option<User>

source§

fn get_session_by_token(&self, token: impl AsRef<str>) -> Option<Session>

source§

fn update_user(&mut self, user: User) -> Result<(), AuthError>

source§

fn add_user(&mut self, user: User) -> Result<(), AuthError>

source§

fn remove_user(&mut self, uid: impl AsRef<str>) -> Result<(), AuthError>

Implementors§