diff --git a/src/app/api/analyze/route.ts b/src/app/api/analyze/route.ts index 0f5d997..d4fd412 100644 --- a/src/app/api/analyze/route.ts +++ b/src/app/api/analyze/route.ts @@ -146,10 +146,18 @@ export async function POST(req: NextRequest): Promise { const formData = await req.formData() const imageFile = formData.get('image') - // Check for wallet address in both form data and headers + // Check for wallet address in form data, URL params, and headers let walletAddress = formData.get('walletAddress'); - // Also check custom header (this is more reliable with Next.js) + // Check URL query parameters (most reliable on Vercel) + const url = new URL(req.url); + const queryWalletAddress = url.searchParams.get('wallet'); + if (queryWalletAddress && !walletAddress) { + console.log('Found wallet address in URL query parameter:', queryWalletAddress); + walletAddress = queryWalletAddress; + } + + // Also check custom header (less reliable with Vercel) const walletHeaderAddress = req.headers.get('X-Wallet-Address'); if (walletHeaderAddress && !walletAddress) { console.log('Found wallet address in custom header:', walletHeaderAddress); @@ -162,8 +170,10 @@ export async function POST(req: NextRequest): Promise { imageType: imageFile ? typeof imageFile : 'undefined', hasWalletAddressInForm: !!formData.get('walletAddress'), hasWalletAddressInHeader: !!walletHeaderAddress, + hasWalletAddressInQuery: !!queryWalletAddress, + requestUrl: req.url, + searchParams: Object.fromEntries(url.searchParams.entries()), finalWalletAddress: walletAddress || 'Not provided', - headers: Object.fromEntries(req.headers.entries()), formDataKeys: Array.from(formData.keys()) }); diff --git a/src/components/WildlifeIdentifier.tsx b/src/components/WildlifeIdentifier.tsx index ab5863c..d4d9efc 100644 --- a/src/components/WildlifeIdentifier.tsx +++ b/src/components/WildlifeIdentifier.tsx @@ -110,19 +110,18 @@ const WildlifeIdentifier: React.FC = () => { console.log('Wallet connection status:', isWalletConnected()); console.log('User wallet address:', userAddress || 'Not connected'); - // Prepare custom headers including wallet address - const headers = new Headers(); - - // Add wallet address as a custom header if available + // Construct the URL with wallet address as a query parameter if available + let url = '/api/analyze'; if (userAddress) { - console.log('Adding wallet address to custom header:', userAddress); - headers.append('X-Wallet-Address', userAddress); + // Encode the wallet address for URL safety + const encodedWalletAddress = encodeURIComponent(userAddress); + url += `?wallet=${encodedWalletAddress}`; + console.log('Adding wallet address as query parameter:', userAddress); } - // Send to the Next.js API route with custom headers - const response = await fetch('/api/analyze', { + // Send to the Next.js API route with wallet in the URL + const response = await fetch(url, { method: 'POST', - headers: headers, body: formData });