diff --git a/src/app/api/analyze/route.ts b/src/app/api/analyze/route.ts index 927cd42..d5e5d1b 100644 --- a/src/app/api/analyze/route.ts +++ b/src/app/api/analyze/route.ts @@ -266,18 +266,36 @@ export async function POST(req: NextRequest): Promise { if (!ensuredUserId) { console.error('Failed to ensure user exists, cannot award points'); - } else { - const pointsResult = await awardPointsForImage( - ensuredUserId, // Use the ensured ID, which might be different from pointsUserId - userEmail, - buffer, - ipfsUrl, - visionResult.description, - visionResult.mainObject - ); - console.log('Points award result:', pointsResult); - // Check for Sei wallet connection and award tokens + // Even if we can't award points, we should still return a successful response + // so the user gets some useful feedback about their image + return NextResponse.json(responseData); + } else { + // Award points first - this should always happen regardless of wallet status + console.log('Attempting to award points for user:', { ensuredUserId, userEmail }); + try { + const pointsResult = await awardPointsForImage( + ensuredUserId, // Use the ensured ID, which might be different from pointsUserId + userEmail, + buffer, + ipfsUrl, + visionResult.description, + visionResult.mainObject + ); + console.log('Points award result:', pointsResult); + + if (pointsResult.success) { + console.log(`Successfully awarded ${pointsResult.points} points to user ${ensuredUserId}`); + } else { + console.warn(`Failed to award points to user ${ensuredUserId}: ${pointsResult.message}`); + } + } catch (pointsError) { + console.error('Error awarding points:', pointsError); + // Even if points award fails, we continue to try token rewards + } + + // AFTER points are awarded, try to award tokens if wallet is connected + // This is separate so issues with token rewards don't affect points try { // Import dynamically to avoid server-side issues with window object const { awardTokensForSighting } = await import('../../../services/blockchain/tokenRewardService');