1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum AuthError {
5 #[error("invalid credentials")]
6 InvalidCredentials,
7
8 #[error("user not found")]
9 UserNotFound,
10
11 #[error("session not found or expired")]
12 SessionNotFound,
13
14 #[error("email already in use")]
15 EmailTaken,
16
17 #[error("email not verified")]
18 EmailNotVerified,
19
20 #[error("token is invalid or expired")]
21 InvalidToken,
22
23 #[error("password hash failed: {0}")]
24 HashError(String),
25
26 #[error("encryption error: {0}")]
27 EncryptionError(String),
28
29 #[error("account locked: too many failed attempts, try again later")]
30 AccountLocked,
31
32 #[error("password too weak")]
33 WeakPassword,
34
35 #[error("access denied: {0}")]
36 Forbidden(String),
37
38 #[error("storage error: {0}")]
39 Storage(#[from] StorageError),
40
41 #[error("internal error: {0}")]
42 Internal(String),
43}
44
45#[derive(Debug, Error)]
46pub enum StorageError {
47 #[error("record not found")]
48 NotFound,
49
50 #[error("constraint violation: {0}")]
51 Conflict(String),
52
53 #[error("database error: {0}")]
54 Database(String),
55}
56
57pub type Result<T> = std::result::Result<T, AuthError>;