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:
@ -11,9 +11,15 @@ const configurePassport = (passport, db) => {
|
||||
},
|
||||
async (accessToken, refreshToken, profile, done) => {
|
||||
try {
|
||||
// Safely extract email
|
||||
const email = profile.emails?.[0]?.value;
|
||||
if (!email) {
|
||||
return done(new Error('No email found in Google profile'), null);
|
||||
}
|
||||
|
||||
const userProfile = {
|
||||
googleId: profile.id,
|
||||
email: profile.emails[0].value,
|
||||
email: email,
|
||||
name: profile.displayName,
|
||||
picture: profile.photos?.[0]?.value || null
|
||||
};
|
||||
@ -21,6 +27,7 @@ const configurePassport = (passport, db) => {
|
||||
const user = await findOrCreateUser(db, userProfile);
|
||||
done(null, user);
|
||||
} catch (error) {
|
||||
console.error('Passport strategy error:', error);
|
||||
done(error, null);
|
||||
}
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user