Skip to main content

rs_auth_core/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error, Clone, PartialEq, Eq)]
4pub enum OAuthError {
5    #[error("unknown provider: {provider}")]
6    ProviderNotFound { provider: String },
7
8    #[error("unsupported provider: {provider}")]
9    UnsupportedProvider { provider: String },
10
11    #[error("oauth provider misconfigured: {message}")]
12    Misconfigured { message: String },
13
14    #[error("oauth state invalid or expired")]
15    InvalidState,
16
17    #[error("oauth token exchange failed")]
18    ExchangeFailed,
19
20    #[error("oauth userinfo request failed")]
21    UserInfoFailed,
22
23    #[error("oauth userinfo payload invalid")]
24    UserInfoMalformed,
25
26    #[error("oauth provider did not return an access token")]
27    MissingAccessToken,
28
29    #[error("oauth provider did not provide a usable email")]
30    MissingEmail,
31
32    #[error("account linking by email is disabled")]
33    LinkingDisabled,
34
35    #[error("account not found")]
36    AccountNotFound,
37
38    #[error("cannot unlink last authentication method")]
39    LastAuthMethod,
40
41    #[error("account already linked to a different user")]
42    AccountAlreadyLinked,
43
44    #[error("token refresh failed")]
45    RefreshFailed,
46
47    #[error("no refresh token available")]
48    NoRefreshToken,
49}
50
51/// Authentication error types.
52#[derive(Debug, Error)]
53pub enum AuthError {
54    #[error("invalid credentials")]
55    InvalidCredentials,
56
57    #[error("email already in use")]
58    EmailTaken,
59
60    #[error("user not found")]
61    UserNotFound,
62
63    #[error("session not found or expired")]
64    SessionNotFound,
65
66    #[error("token invalid or expired")]
67    InvalidToken,
68
69    #[error("email not verified")]
70    EmailNotVerified,
71
72    #[error("password must be at least {0} characters")]
73    WeakPassword(usize),
74
75    #[error("hash error: {0}")]
76    Hash(String),
77
78    #[error("store error: {0}")]
79    Store(String),
80
81    #[error("internal error: {0}")]
82    Internal(String),
83
84    #[error("oauth error: {0}")]
85    OAuth(#[from] OAuthError),
86}