From 29c6f9389bfc82f70704980082c02db996db008e Mon Sep 17 00:00:00 2001 From: zramsay Date: Tue, 11 Mar 2025 18:27:38 -0400 Subject: [PATCH] ffffffs --- src/services/userPointsService.ts | 33 ++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/services/userPointsService.ts b/src/services/userPointsService.ts index c841efd..1f9f7a4 100644 --- a/src/services/userPointsService.ts +++ b/src/services/userPointsService.ts @@ -61,7 +61,7 @@ export async function initializeUser(userId: string, email: string) { .insert({ user_id: userIdUUID, email: email, - total_points: 0 + total_points: 0 // Start with 0 points for new users }) .select() .single(); @@ -77,7 +77,7 @@ export async function initializeUser(userId: string, email: string) { .rpc('create_user_points', { user_id_param: userIdUUID, email_param: email, - initial_points: 0 + initial_points: 0 // Start with 0 points for new users }); if (error) { @@ -90,7 +90,7 @@ export async function initializeUser(userId: string, email: string) { .insert({ user_id: userIdUUID, email, - total_points: 0 + total_points: 0 // Start with 0 points for new users }) .select() .single(); @@ -134,10 +134,22 @@ export async function awardPointsForImage( }; } - // If userId is an email, use it for deterministic UUID generation - if (userId.includes('@') && email) { - console.log('userId is an email, using it for consistent UUID generation'); - userId = email; // Use email for consistency + // If userId is an email, use it for consistent storage + if (userId.includes('@')) { + console.log('userId is an email, using it as the email field'); + // But keep the userId as is for consistent UUID generation + } + + // If email is missing but userId looks like an email, use that + if (!email && userId.includes('@')) { + email = userId; + console.log('Using userId as email since it contains @:', email); + } + + // Ensure we have a valid email + if (!email || email === 'unknown@example.com') { + email = userId.includes('@') ? userId : `${userId}@user.wildlife.app`; + console.log('Generated proper email for points system:', email); } // Convert userId to UUID format @@ -341,10 +353,9 @@ export async function getUserPoints(userId: string) { email = userId; // Use the userId as email if it is one console.log('Using email from userId for initialization:', email); } else { - // Use a dummy email if we don't have a real one - const userIdForEmail = validateUuid(userId) ? userId : userId.substring(0, 8); - email = userIdForEmail + '@example.com'; // Fallback email - console.log('Using dummy email for initialization:', email); + // Use a real email format if possible - but don't use example.com + email = userId.includes('@') ? userId : `${userId}@user.wildlife.app`; + console.log('Using generated email for initialization:', email); } await initializeUser(userId, email);