diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-09-18 01:27:47 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-09-18 12:17:46 -0400 |
| commit | cce6662d635bb2115f9f2a7bab92cc105166e761 (patch) | |
| tree | 9d1edfea364a3b72cf40c78d67ce05e3e68c84df /src/repo/login | |
| parent | 921f38a73e5d58a5a6077477a8b52d2705798f55 (diff) | |
App methods now return errors that allow not-found cases to be distinguished.
Diffstat (limited to 'src/repo/login')
| -rw-r--r-- | src/repo/login/extract.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/repo/login/extract.rs b/src/repo/login/extract.rs index a068bc0..a45a1cd 100644 --- a/src/repo/login/extract.rs +++ b/src/repo/login/extract.rs @@ -5,7 +5,12 @@ use axum::{ }; use super::Login; -use crate::{app::App, clock::RequestedAt, error::InternalError, login::extract::IdentityToken}; +use crate::{ + app::App, + clock::RequestedAt, + error::InternalError, + login::{app::ValidateError, extract::IdentityToken}, +}; #[async_trait::async_trait] impl FromRequestParts<App> for Login { @@ -22,9 +27,11 @@ impl FromRequestParts<App> for Login { let secret = identity_token.secret().ok_or(LoginError::Unauthorized)?; let app = State::<App>::from_request_parts(parts, state).await?; - let login = app.logins().validate(secret, used_at).await?; - - login.ok_or(LoginError::Unauthorized) + match app.logins().validate(secret, used_at).await { + Ok(login) => Ok(login), + Err(ValidateError::InvalidToken) => Err(LoginError::Unauthorized), + Err(other) => Err(other.into()), + } } } |
