Fix all compile warnings in frontend and backend
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 <noreply@anthropic.com>
This commit is contained in:
60
src/auth.rs
60
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<UserInfo, String> {
|
||||
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<T: Serialize, R: for<'de> 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<serde_json::Value, String> {
|
||||
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::<serde_json::Value>(&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::<ApiErrorResponse>(&text_string) {
|
||||
Err(error_response.error)
|
||||
} else {
|
||||
Err(format!("Request failed with status {}", resp.status()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user