diff --git a/Cargo.lock b/Cargo.lock index 9a7f79d..1c9d1c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -360,6 +360,7 @@ dependencies = [ "shared", "sqlx", "thiserror 2.0.18", + "time", "tokio", "tokio-stream", "tokio-util", @@ -907,6 +908,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587" dependencies = [ "powerfmt", + "serde_core", ] [[package]] diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 08c30a4..b8fbb4f 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -38,3 +38,4 @@ bcrypt = "0.17.0" axum-extra = { version = "0.9", features = ["cookie"] } rand = "0.8" anyhow = "1.0.101" +time = { version = "0.3.47", features = ["serde", "formatting", "parsing"] } diff --git a/backend/src/handlers/auth.rs b/backend/src/handlers/auth.rs index b517ff6..c113d99 100644 --- a/backend/src/handlers/auth.rs +++ b/backend/src/handlers/auth.rs @@ -15,7 +15,7 @@ pub struct LoginRequest { password: String, } -#[derive(Serialize)] +#[derive(Serialize, ToSchema)] pub struct UserResponse { username: String, } @@ -76,6 +76,13 @@ pub async fn login_handler( } } +#[utoipa::path( + post, + path = "/api/auth/logout", + responses( + (status = 200, description = "Logged out") + ) +)] pub async fn logout_handler( State(state): State, jar: CookieJar, @@ -93,6 +100,14 @@ pub async fn logout_handler( (StatusCode::OK, jar.add(cookie), "Logged out").into_response() } +#[utoipa::path( + get, + path = "/api/auth/check", + responses( + (status = 200, description = "Authenticated"), + (status = 401, description = "Not authenticated") + ) +)] pub async fn check_auth_handler( State(state): State, jar: CookieJar, diff --git a/backend/src/handlers/setup.rs b/backend/src/handlers/setup.rs index 1bfffbd..b85ac0b 100644 --- a/backend/src/handlers/setup.rs +++ b/backend/src/handlers/setup.rs @@ -13,7 +13,7 @@ pub struct SetupRequest { password: String, } -#[derive(Serialize)] +#[derive(Serialize, ToSchema)] pub struct SetupStatusResponse { completed: bool, } diff --git a/backend/src/main.rs b/backend/src/main.rs index 5e2682a..4c7e744 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -12,9 +12,8 @@ use axum::{ routing::{get, post}, Router, middleware::{self, Next}, - extract::Request, response::Response, - http::StatusCode, + http::{StatusCode, Request}, body::Body, }; use axum_extra::extract::cookie::CookieJar; @@ -47,7 +46,7 @@ pub struct AppState { async fn auth_middleware( state: axum::extract::State, jar: CookieJar, - request: Request, + request: Request, next: Next, ) -> Result { // Skip auth for public paths @@ -72,7 +71,6 @@ async fn auth_middleware( Err(StatusCode::UNAUTHORIZED) } - #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] struct Args {