This commit is contained in:
zramsay 2025-03-11 18:27:38 -04:00
parent 24d8a3e8f1
commit 29c6f9389b

View File

@ -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);