other: temp save

This commit is contained in:
2025-01-11 15:02:04 +08:00
parent 8f76e92804
commit 97b7bfb7fb
16 changed files with 229 additions and 278 deletions

View File

@@ -1,6 +1,7 @@
use axum::{
http::StatusCode,
response::{IntoResponse, Response},
Json,
};
use thiserror::Error;
@@ -30,6 +31,6 @@ pub enum AuthError {
impl IntoResponse for AuthError {
fn into_response(self) -> Response {
(StatusCode::UNAUTHORIZED, self.to_string()).into_response()
(StatusCode::UNAUTHORIZED, Json(self.to_string())).into_response()
}
}

View File

@@ -3,7 +3,6 @@ use axum::{
extract::FromRequestParts,
http::request::Parts,
response::{IntoResponse as _, Response},
Extension,
};
use jwt_authorizer::{JwtAuthorizer, Validation};
use loco_rs::app::{AppContext, Initializer};
@@ -22,21 +21,17 @@ pub struct AuthUserInfo {
pub auth_type: AuthType,
}
impl<S> FromRequestParts<S> for AuthUserInfo
where
S: Send + Sync,
{
impl FromRequestParts<AppContext> for AuthUserInfo {
type Rejection = Response;
async fn from_request_parts(req: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
let Extension(ctx) = Extension::<AppContext>::from_request_parts(req, state)
.await
.expect("AppContext should be present");
let auth_service = ctx.get_auth_service();
async fn from_request_parts(
parts: &mut Parts,
state: &AppContext,
) -> Result<Self, Self::Rejection> {
let auth_service = state.get_auth_service();
auth_service
.extract_user_info(req)
.extract_user_info(parts)
.await
.map_err(|err| err.into_response())
}