feat: add visibility feature to thoughts, including new enum, database migration, and update related endpoints and tests
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
mod auth;
|
||||
mod json;
|
||||
mod optional_auth;
|
||||
mod valid;
|
||||
|
||||
pub use auth::AuthUser;
|
||||
pub use auth::Claims;
|
||||
pub use json::Json;
|
||||
pub use optional_auth::OptionalAuthUser;
|
||||
pub use valid::Valid;
|
||||
|
||||
21
thoughts-backend/api/src/extractor/optional_auth.rs
Normal file
21
thoughts-backend/api/src/extractor/optional_auth.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use super::AuthUser;
|
||||
use crate::error::ApiError;
|
||||
use app::state::AppState;
|
||||
use axum::{extract::FromRequestParts, http::request::Parts};
|
||||
|
||||
pub struct OptionalAuthUser(pub Option<AuthUser>);
|
||||
|
||||
impl FromRequestParts<AppState> for OptionalAuthUser {
|
||||
type Rejection = ApiError;
|
||||
|
||||
async fn from_request_parts(
|
||||
parts: &mut Parts,
|
||||
state: &AppState,
|
||||
) -> Result<Self, Self::Rejection> {
|
||||
match AuthUser::from_request_parts(parts, state).await {
|
||||
Ok(user) => Ok(OptionalAuthUser(Some(user))),
|
||||
// If the user is not authenticated for any reason, we just treat them as a guest.
|
||||
Err(_) => Ok(OptionalAuthUser(None)),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user