From 4a192519ac9a71a1ba4b4bc73d68d54575e45aa6 Mon Sep 17 00:00:00 2001 From: zramsay Date: Fri, 21 Mar 2025 21:36:21 -0400 Subject: [PATCH] build --- src/app/api/award-tokens/route.ts | 38 ++++++++++++++++------------ src/components/ImageAnalysisCard.tsx | 2 ++ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/app/api/award-tokens/route.ts b/src/app/api/award-tokens/route.ts index 719b57b..a0cf75d 100644 --- a/src/app/api/award-tokens/route.ts +++ b/src/app/api/award-tokens/route.ts @@ -1,65 +1,71 @@ import { NextRequest, NextResponse } from 'next/server'; -import { getServerSession } from 'next-auth'; -import { authOptions } from '@/lib/auth'; +import { getSessionFromCookie, getUserFromHeaders } from '@/lib/auth'; import { awardTokensForSighting } from '@/services/blockchain/tokenRewardService'; -import { logger } from '@/services/constants'; export async function POST(req: NextRequest) { try { - logger.info('award-tokens API called'); + console.log('award-tokens API called'); // Log all request headers for debugging - logger.info('Request headers:', Object.fromEntries(req.headers.entries())); + console.log('Request headers:', Object.fromEntries(req.headers.entries())); // Make authentication optional for demonstration - we'll allow both authenticated and // unauthenticated requests for testing purposes let userEmail = 'unknown@example.com'; try { - const session = await getServerSession(authOptions); + // Try to get session from cookie first + const session = await getSessionFromCookie(req); + + // Also try header-based authentication + const headerUser = getUserFromHeaders(req); + if (session?.user?.email) { userEmail = session.user.email; - logger.info(`Authenticated user: ${userEmail}`); + console.log(`Authenticated user from session: ${userEmail}`); + } else if (headerUser?.email) { + userEmail = headerUser.email; + console.log(`Authenticated user from headers: ${userEmail}`); } else { - logger.warn('No authenticated session found, but continuing for demonstration'); + console.warn('No authenticated session found, but continuing for demonstration'); } } catch (authError) { - logger.error('Authentication error but continuing:', authError); + console.error('Authentication error but continuing:', authError); } // Parse request body let data; try { data = await req.json(); - logger.info('Request body:', data); + console.log('Request body:', data); } catch (parseError) { - logger.error('Failed to parse request body:', parseError); + console.error('Failed to parse request body:', parseError); return NextResponse.json({ error: 'Invalid request body' }, { status: 400 }); } const { walletAddress, animalName } = data; if (!walletAddress) { - logger.error('No wallet address provided for token award'); + console.error('No wallet address provided for token award'); return NextResponse.json({ error: 'Wallet address is required' }, { status: 400 }); } - logger.info(`Processing token award for wallet ${walletAddress} and animal ${animalName || 'Unknown'}`); + console.log(`Processing token award for wallet ${walletAddress} and animal ${animalName || 'Unknown'}`); // Check for environment variables const apiUrl = process.env.NEXT_PUBLIC_TOKEN_BACKEND_URL; const apiKey = process.env.NEXT_PUBLIC_TOKEN_API_KEY; - logger.info(`Using backend URL: ${apiUrl || 'Not set'}, API key exists: ${!!apiKey}`); + console.log(`Using backend URL: ${apiUrl || 'Not set'}, API key exists: ${!!apiKey}`); const result = await awardTokensForSighting(walletAddress, userEmail, animalName || 'Unknown wildlife'); - logger.info(`Token award result:`, result); + console.log(`Token award result:`, result); // Return the complete result directly without nesting return NextResponse.json(result); } catch (error) { - logger.error('Error in award-tokens API:', error); + console.error('Error in award-tokens API:', error); return NextResponse.json({ success: false, error: error instanceof Error ? error.message : 'Failed to award tokens' diff --git a/src/components/ImageAnalysisCard.tsx b/src/components/ImageAnalysisCard.tsx index 7bc11cd..382421c 100644 --- a/src/components/ImageAnalysisCard.tsx +++ b/src/components/ImageAnalysisCard.tsx @@ -16,6 +16,8 @@ interface AnalysisResult { error?: string; isAnimal?: boolean; tokenReward?: TokenReward | null; + animalType?: string; + pointsAwarded?: number; } interface ImageAnalysisCardProps {