From 7a7c42079d5d2d68622f475665dc0aa2a0c0a342 Mon Sep 17 00:00:00 2001 From: zramsay Date: Tue, 11 Mar 2025 17:53:06 -0400 Subject: [PATCH] user fixes --- src/app/api/analyze/route.ts | 12 ++++++++---- src/app/page.tsx | 5 ++++- src/types/auth.d.ts | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) 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;