Add middleware to check authentication
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
use crate::app_config::AppConfig;
|
||||
use crate::extractors::auth_extractor::AuthChecker;
|
||||
use crate::extractors::auth_extractor::AuthExtractor;
|
||||
use crate::extractors::local_auth_extractor::LocalAuthEnabled;
|
||||
use actix_web::{web, HttpResponse, Responder};
|
||||
|
||||
@ -13,7 +13,7 @@ pub struct LocalAuthReq {
|
||||
pub async fn local_auth(
|
||||
local_auth_enabled: LocalAuthEnabled,
|
||||
req: web::Json<LocalAuthReq>,
|
||||
auth: AuthChecker,
|
||||
auth: AuthExtractor,
|
||||
) -> impl Responder {
|
||||
if !*local_auth_enabled {
|
||||
log::error!("Local auth attempt while this authentication method is disabled!");
|
||||
@ -29,3 +29,15 @@ pub async fn local_auth(
|
||||
|
||||
HttpResponse::Accepted().json("Welcome")
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
struct CurrentUser {
|
||||
id: String,
|
||||
}
|
||||
|
||||
/// Get current authenticated user
|
||||
pub async fn current_user(auth: AuthExtractor) -> impl Responder {
|
||||
HttpResponse::Ok().json(CurrentUser {
|
||||
id: auth.id().unwrap(),
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user