use crate::{auth::Auth, state::ReqState}; use axum::{extract::State, response::IntoResponse}; use hyper::StatusCode; pub async fn post(State(state): ReqState, Auth(auth): Auth) -> impl IntoResponse { if !auth.admin { return Err(StatusCode::UNAUTHORIZED); } let key = crate::utils::gen_key(); sqlx::query!("insert into api_keys (key, admin) values ($1, false)", key) .execute(&state.db) .await .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; Ok((StatusCode::CREATED, key)) }