Skip to main content

waveless_commons/auth/
mod.rs

1// Waveless
2// Copyright (C) 2026 Oscar Alvarez Gonzalez
3
4mod role;
5mod session;
6
7pub use role::*;
8pub use session::*;
9
10use crate::*;
11
12use databases::*;
13
14/// Trait implemented for every user authentication mechanism.
15/// Note that the auth data does not have to live in a SQL database...
16#[typetag::serde]
17#[async_trait]
18pub trait AnyAuthenticationMethod: AnyExt + DatabaseConsumer {
19    /// Check whether the given credentials match for a given user.
20    async fn check(
21        &self,
22        db_conns: DbConns,
23        entries: HashMap<CompactString, CompactString>,
24    ) -> Result<Option<UserId>>;
25
26    /// Signup a new user.
27    async fn new(
28        &self,
29        db_conns: DbConns,
30        entries: HashMap<CompactString, CompactString>,
31    ) -> Result<UserId>;
32
33    /// Deletes a user given it's id.
34    async fn delete(&self, db_conns: DbConns, user_id: UserId) -> Result<()>;
35}