this repo has no description
1use axum::{
2 Json,
3 extract::State,
4 http::{HeaderMap, StatusCode},
5 response::{IntoResponse, Response},
6};
7use serde::Serialize;
8use serde_json::json;
9use crate::auth::{extract_bearer_token_from_header, validate_bearer_token};
10use crate::state::AppState;
11
12#[derive(Serialize)]
13#[serde(rename_all = "camelCase")]
14pub struct CheckSignupQueueOutput {
15 pub activated: bool,
16 #[serde(skip_serializing_if = "Option::is_none")]
17 pub place_in_queue: Option<i64>,
18 #[serde(skip_serializing_if = "Option::is_none")]
19 pub estimated_time_ms: Option<i64>,
20}
21
22pub async fn check_signup_queue(
23 State(state): State<AppState>,
24 headers: HeaderMap,
25) -> Response {
26 if let Some(token) = extract_bearer_token_from_header(
27 headers.get("Authorization").and_then(|h| h.to_str().ok())
28 ) {
29 if let Ok(user) = validate_bearer_token(&state.db, &token).await {
30 if user.is_oauth {
31 return (
32 StatusCode::FORBIDDEN,
33 Json(json!({
34 "error": "Forbidden",
35 "message": "OAuth credentials are not supported for this endpoint"
36 })),
37 ).into_response();
38 }
39 }
40 }
41 Json(CheckSignupQueueOutput {
42 activated: true,
43 place_in_queue: None,
44 estimated_time_ms: None,
45 }).into_response()
46}