diff --git a/src/app/api/analyze/route.ts b/src/app/api/analyze/route.ts index dd89730..efe056e 100644 --- a/src/app/api/analyze/route.ts +++ b/src/app/api/analyze/route.ts @@ -191,10 +191,14 @@ export async function POST(req: NextRequest): Promise { // Award points to the user for uploading a valid animal image // We've already extracted user info in the authentication section above - if (userId && userEmail) { - console.log('Awarding points to user:', { userId, userEmail }); + // Use email as ID if needed - this allows points to be accumulated + // even if the user ID is not available from the session + const pointsUserId = userId || userEmail; + + if (pointsUserId && userEmail) { + console.log('Awarding points to user:', { pointsUserId, userEmail }); await awardPointsForImage( - userId, + pointsUserId, userEmail, buffer, ipfsUrl, @@ -203,7 +207,7 @@ export async function POST(req: NextRequest): Promise { ).catch(err => console.error('Failed to award points for image:', err)); } else { console.log('Unable to award points, missing user data', { - userId, + pointsUserId, userEmail }); } diff --git a/src/app/page.tsx b/src/app/page.tsx index 3b22e8c..b625681 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -43,10 +43,13 @@ const Page: React.FC = (): React.ReactElement => { // Prepare session data for API call let sessionData; if (isAuthenticated && session && session.user) { + // Use email as a fallback ID if id is undefined sessionData = { - userId: session.user.id, + userId: session.user.id || session.user.email || '', userEmail: session.user.email || '' }; + + console.log('Session data being sent to API:', sessionData); } // Analyze the normalized image with session data diff --git a/src/types/auth.d.ts b/src/types/auth.d.ts index 525de87..8e2601f 100644 --- a/src/types/auth.d.ts +++ b/src/types/auth.d.ts @@ -3,7 +3,7 @@ import "next-auth"; declare module "next-auth" { interface Session { user: { - id: string; + id?: string; name?: string | null; email?: string | null; image?: string | null;