From b7b351416d1e5f01665a2ee7fac6beea4bee72d0 Mon Sep 17 00:00:00 2001 From: Connor Johnstone Date: Thu, 28 Aug 2025 16:33:07 -0400 Subject: [PATCH] Fix all compile warnings in frontend and backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed unused imports, fields, methods, and structs that were generating warnings during compilation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- backend/src/auth.rs | 2 +- backend/src/handlers.rs | 9 ++----- backend/src/lib.rs | 7 +---- src/auth.rs | 60 ----------------------------------------- 4 files changed, 4 insertions(+), 74 deletions(-) diff --git a/backend/src/auth.rs b/backend/src/auth.rs index 912b11f..eb11130 100644 --- a/backend/src/auth.rs +++ b/backend/src/auth.rs @@ -1,5 +1,5 @@ use bcrypt::{hash, verify, DEFAULT_COST}; -use chrono::{DateTime, Duration, Utc}; +use chrono::{Duration, Utc}; use jsonwebtoken::{decode, encode, Algorithm, DecodingKey, EncodingKey, Header, Validation}; use serde::{Deserialize, Serialize}; use sqlx::{Row, SqlitePool}; diff --git a/backend/src/handlers.rs b/backend/src/handlers.rs index 645045b..9422794 100644 --- a/backend/src/handlers.rs +++ b/backend/src/handlers.rs @@ -1,17 +1,12 @@ use axum::{ - extract::{Query, State}, - http::{HeaderMap, StatusCode}, + extract::State, + http::HeaderMap, response::Json, }; -use serde::Deserialize; use std::sync::Arc; use crate::{AppState, models::{LoginRequest, RegisterRequest, AuthResponse, ApiError}}; -#[derive(Deserialize)] -pub struct VerifyQuery { - pub token: String, -} pub async fn register( State(state): State>, diff --git a/backend/src/lib.rs b/backend/src/lib.rs index c032831..63be15b 100644 --- a/backend/src/lib.rs +++ b/backend/src/lib.rs @@ -1,14 +1,10 @@ use axum::{ - extract::State, - http::StatusCode, response::Json, routing::{get, post}, Router, }; -use serde::{Deserialize, Serialize}; -use sqlx::{sqlite::SqlitePool, Row}; +use sqlx::sqlite::SqlitePool; use tower_http::cors::{CorsLayer, Any}; -use uuid::Uuid; use std::sync::Arc; mod auth; @@ -16,7 +12,6 @@ mod models; mod handlers; use auth::AuthService; -use models::{LoginRequest, RegisterRequest, AuthResponse, ApiError}; #[derive(Clone)] pub struct AppState { diff --git a/src/auth.rs b/src/auth.rs index bc39aa7..103debe 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -40,7 +40,6 @@ pub struct AuthResponse { #[derive(Debug, Deserialize)] pub struct ApiErrorResponse { pub error: String, - pub status: u16, } // Frontend auth service - connects to backend API @@ -66,18 +65,6 @@ impl AuthService { self.post_json("/auth/login", &request).await } - pub async fn verify_token(&self, token: &str) -> Result { - let response = self.get_with_auth("/auth/verify", token).await?; - let json_value: serde_json::Value = response; - - if let Some(user_obj) = json_value.get("user") { - serde_json::from_value(user_obj.clone()) - .map_err(|e| format!("Failed to parse user info: {}", e)) - } else { - Err("Invalid response format".to_string()) - } - } - // Helper method for POST requests with JSON body async fn post_json Deserialize<'de>>( &self, @@ -128,51 +115,4 @@ impl AuthService { } } } - - // Helper method for GET requests with Authorization header - async fn get_with_auth( - &self, - endpoint: &str, - token: &str, - ) -> Result { - let window = web_sys::window().ok_or("No global window exists")?; - - let opts = RequestInit::new(); - opts.set_method("GET"); - opts.set_mode(RequestMode::Cors); - - let url = format!("{}{}", self.base_url, endpoint); - let request = Request::new_with_str_and_init(&url, &opts) - .map_err(|e| format!("Request creation failed: {:?}", e))?; - - request.headers().set("Authorization", &format!("Bearer {}", token)) - .map_err(|e| format!("Authorization header setting failed: {:?}", e))?; - - let resp_value = JsFuture::from(window.fetch_with_request(&request)) - .await - .map_err(|e| format!("Network request failed: {:?}", e))?; - - let resp: Response = resp_value.dyn_into() - .map_err(|e| format!("Response cast failed: {:?}", e))?; - - let text = JsFuture::from(resp.text() - .map_err(|e| format!("Text extraction failed: {:?}", e))?) - .await - .map_err(|e| format!("Text promise failed: {:?}", e))?; - - let text_string = text.as_string() - .ok_or("Response text is not a string")?; - - if resp.ok() { - serde_json::from_str::(&text_string) - .map_err(|e| format!("JSON parsing failed: {}", e)) - } else { - // Try to parse error response - if let Ok(error_response) = serde_json::from_str::(&text_string) { - Err(error_response.error) - } else { - Err(format!("Request failed with status {}", resp.status())) - } - } - } } \ No newline at end of file