simple-web-app

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit cd049f485f188ba3f87896e04e71bf4dde2599aa
parent 358bd6937a5bec8c1d54819bc89b689a81a1c6e3
Author: Silas Brack <silasbrack@gmail.com>
Date:   Sat, 25 Apr 2026 17:49:04 +0200

debug: add logging for user_id extraction and create operations

Diffstat:
Msrc/trailbase.rs | 40++++++++++++++++++++++++++++++++++++----
1 file changed, 36 insertions(+), 4 deletions(-)

diff --git a/src/trailbase.rs b/src/trailbase.rs @@ -36,6 +36,7 @@ pub fn extract_user_id_from_token(auth_token: &str) -> Option<String> { // JWT format: header.payload.signature let parts: Vec<&str> = auth_token.split('.').collect(); if parts.len() != 3 { + tracing::warn!("JWT has {} parts, expected 3", parts.len()); return None; } @@ -43,9 +44,15 @@ pub fn extract_user_id_from_token(auth_token: &str) -> Option<String> { let payload = base64_decode_url_safe(parts[1])?; let payload_str = String::from_utf8(payload).ok()?; + tracing::debug!("JWT payload: {}", payload_str); + // Parse as JSON and extract "sub" claim let json: serde_json::Value = serde_json::from_str(&payload_str).ok()?; - json.get("sub").and_then(|v| v.as_str()).map(|s| s.to_string()) + let sub = json.get("sub").and_then(|v| v.as_str()).map(|s| s.to_string()); + + tracing::info!("Extracted sub from JWT: {:?}", sub); + + sub } /// URL-safe base64 decode (handles missing padding) @@ -306,6 +313,9 @@ pub async fn create_comment(client: &Client, comment: CreateComment) -> Result<C let tokens = client.tokens().ok_or_else(|| ClientError::Auth("Not authenticated".to_string()))?; let user_id = extract_user_id_from_token(&tokens.auth_token) .ok_or_else(|| ClientError::Auth("Invalid token".to_string()))?; + + tracing::info!("Creating comment with user_id: {}", user_id); + let comment_with_user = CreateCommentWithUser { story_id: comment.story_id, parent_id: comment.parent_id, @@ -314,7 +324,17 @@ pub async fn create_comment(client: &Client, comment: CreateComment) -> Result<C text: comment.text, created_by: user_id, }; - let id_str = client.records("comment").create(&comment_with_user).await?; + + let id_str = match client.records("comment").create(&comment_with_user).await { + Ok(id) => { + tracing::info!("Comment created with id: {}", id); + id + } + Err(e) => { + tracing::error!("Failed to create comment: {:?}", e); + return Err(e.into()); + } + }; let id: i64 = id_str.parse().unwrap_or(0); // Fetch the created comment @@ -391,13 +411,25 @@ pub async fn vote(client: &Client, target_type: i64, target_id: i64) -> Result<( let tokens = client.tokens().ok_or_else(|| ClientError::Auth("Not authenticated".to_string()))?; let user_id = extract_user_id_from_token(&tokens.auth_token) .ok_or_else(|| ClientError::Auth("Invalid token".to_string()))?; + + tracing::info!("Creating vote with user_id: {}", user_id); + let vote_data = CreateVote { user_id, target_type, target_id, }; - client.records("vote").create(&vote_data).await?; - Ok(()) + + match client.records("vote").create(&vote_data).await { + Ok(id) => { + tracing::info!("Vote created with id: {}", id); + Ok(()) + } + Err(e) => { + tracing::error!("Failed to create vote: {:?}", e); + Err(e.into()) + } + } } /// Remove a vote