feat: added auth by api key

This commit is contained in:
Boris Cherepanov
2026-03-23 12:07:57 +03:00
parent 71d5a38f21
commit f26135ca25
4 changed files with 46 additions and 19 deletions
+3 -2
View File
@@ -13,6 +13,7 @@ pub struct AppState {
#[allow(dead_code)]
pub storage_dir: Arc<PathBuf>,
pub oidc: Option<Arc<auth::OidcState>>,
pub api_key: Option<String>,
}
pub fn build_router(state: Arc<AppState>) -> Router {
@@ -32,9 +33,9 @@ pub fn build_router(state: Arc<AppState>) -> Router {
.route("/", get(player_html))
.nest("/api", library);
let has_oidc = state.oidc.is_some();
let requires_auth = state.oidc.is_some();
let app = if has_oidc {
let app = if requires_auth {
authed
.route_layer(middleware::from_fn_with_state(state.clone(), auth::require_auth))
} else {