Skip to main content

doido_auth/
error.rs

1//! Typed auth errors (`thiserror` per crate, per the framework convention).
2
3/// Errors raised by the auth layer.
4#[derive(Debug, thiserror::Error)]
5pub enum AuthError {
6    /// Email/password combination is wrong or the account has no password.
7    #[error("auth: invalid credentials")]
8    InvalidCredentials,
9
10    /// Registration attempted with an email that is already taken.
11    #[error("auth: email already taken")]
12    EmailTaken,
13
14    /// No authenticated identity was found on the request.
15    #[error("auth: unauthorized")]
16    Unauthorized,
17
18    /// A bearer or JWT token is missing or malformed.
19    #[error("auth: invalid token")]
20    InvalidToken,
21
22    /// JWT verification failed (wrong secret, expired, etc.).
23    #[error("auth: jwt error: {0}")]
24    Jwt(String),
25
26    /// OAuth provider or callback failed.
27    #[error("auth: oauth error: {0}")]
28    OAuth(String),
29
30    /// Two-factor verification failed.
31    #[cfg(feature = "auth-2fa")]
32    #[error("auth: two-factor error: {0}")]
33    TwoFactor(String),
34
35    /// The `auth` configuration is invalid or incomplete.
36    #[error("auth: config error: {0}")]
37    Config(String),
38
39    /// An unknown auth strategy was referenced in config.
40    #[error("auth: unknown strategy: {0}")]
41    UnknownStrategy(String),
42
43    /// Database or internal failure.
44    #[error("auth: internal error: {0}")]
45    Internal(String),
46}
47
48impl From<jsonwebtoken::errors::Error> for AuthError {
49    fn from(e: jsonwebtoken::errors::Error) -> Self {
50        AuthError::Jwt(e.to_string())
51    }
52}