use actix_web::web::{Data, Query}; use actix_web::{get, HttpResponse}; use serde::Deserialize; use tokio::sync::mpsc; use crate::auth::AuthCode; #[derive(Debug, Deserialize)] struct AuthCodeQuery { error_reason: Option, code: Option, } #[get("/")] async fn retrieve_auth_code( query: Query, done_tx: Data>, ) -> HttpResponse { if let Some(error_reason) = &query.error_reason { return HttpResponse::Unauthorized().body(format!( "Error: No authentication code was retrieved. Reason: {}\n\nYou can close this tab", error_reason )); } let auth_code = match &query.code { Some(auth_code) => auth_code, None => { return HttpResponse::BadRequest() .body("Error: No authentication code was retrieved"); } }; done_tx.send(auth_code.clone()).await.unwrap(); HttpResponse::Ok() .body("Authentication code was successfully retrieved.\n\nYou can close this tab") }