- Implemented connecting multiple accounts for google

This commit is contained in:
Dejan
2024-10-20 18:34:48 +02:00
parent 80cc184498
commit bb72c6c011
4 changed files with 90 additions and 51 deletions

View File

@ -188,11 +188,17 @@ exports.refreshTokens = functions.pubsub.schedule('every 12 hours').onRun(async
profilesSnapshot.forEach(async (profileDoc) => {
const profileData = profileDoc.data();
if (profileData.googleToken) {
if (profileData.googleAccounts) {
try {
const refreshedGoogleToken = await refreshGoogleToken(profileData.googleToken);
await profileDoc.ref.update({googleToken: refreshedGoogleToken});
console.log(`Google token updated for user ${profileDoc.id}`);
for (const googleEmail of Object.keys(profileData?.googleAccounts)) {
const googleToken = profileData?.googleAccounts?.[googleEmail];
if (googleToken) {
const refreshedGoogleToken = await refreshGoogleToken(googleToken);
const updatedGoogleAccounts = {...profileData.googleAccounts, [googleEmail]: refreshedGoogleToken};
await profileDoc.ref.update({googleAccounts: updatedGoogleAccounts});
console.log(`Google token updated for user ${profileDoc.id}`);
}
}
} catch (error) {
console.error(`Error refreshing Google token for user ${profileDoc.id}:`, error.message);
}