Fix timezone mismatch and OAuth profile field access
- Add getLatestDateWithData() helper that queries the most recent date with price data instead of using server UTC time - Cache latest date for 5 minutes to reduce database queries - Update all date-dependent endpoints to use database-relative dates - Fix OAuth callback profile field access (use profile.email instead of profile.emails[0].value) - Remove loginCount from $setOnInsert to avoid MongoDB conflict error
This commit is contained in:
@ -18,21 +18,20 @@ async function findOrCreateUser(db, profile) {
|
||||
const now = new Date();
|
||||
|
||||
const result = await db.collection(USER_COLLECTION).findOneAndUpdate(
|
||||
{ googleId: profile.id },
|
||||
{ googleId: profile.googleId },
|
||||
{
|
||||
$set: {
|
||||
email: profile.emails[0].value,
|
||||
name: profile.displayName,
|
||||
picture: profile.photos?.[0]?.value || null,
|
||||
email: profile.email,
|
||||
name: profile.name,
|
||||
picture: profile.picture || null,
|
||||
lastLoginAt: now
|
||||
},
|
||||
$inc: { loginCount: 1 },
|
||||
$setOnInsert: {
|
||||
googleId: profile.id,
|
||||
googleId: profile.googleId,
|
||||
isActive: true,
|
||||
role: 'user',
|
||||
createdAt: now,
|
||||
loginCount: 0 // Will be incremented to 1 by $inc
|
||||
createdAt: now
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user