1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum AuthError {
8 #[error("Invalid credentials")]
10 InvalidCredentials,
11
12 #[error("Invalid or expired session")]
14 InvalidSession,
15
16 #[error("User not found")]
18 UserNotFound,
19
20 #[error("Session has expired")]
22 SessionExpired,
23
24 #[error("Database error: {0}")]
26 Database(String),
27
28 #[error("Password hashing error: {0}")]
30 PasswordHash(String),
31
32 #[error("Internal error: {0}")]
34 Internal(String),
35}
36
37impl From<bcrypt::BcryptError> for AuthError {
38 fn from(err: bcrypt::BcryptError) -> Self {
39 AuthError::PasswordHash(err.to_string())
40 }
41}
42
43pub type AuthResult<T> = Result<T, AuthError>;