Skip to content

Commit

Permalink
fix: With Credential Sync enabled, fix expired google calendar token …
Browse files Browse the repository at this point in the history
…handling - Refresh wasn't working (#14788)

Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
  • Loading branch information
hariombalhara and joeauyeung committed Apr 29, 2024
1 parent 46ffeae commit 900e90c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/app-store/googlecalendar/lib/CalendarService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ export default class GoogleCalendarService implements Calendar {
this.credential = credential;
this.auth = this.initGoogleAuth(credential);
this.log = log.getSubLogger({ prefix: [`[[lib] ${this.integrationName}`] });
this.credential = credential;
}

private async getMyGoogleAuthSingleton() {
const googleCredentials = OAuth2UniversalSchema.parse(this.credential.key);
if (this.myGoogleAuth) {
return this.myGoogleAuth;
}
const { client_id, client_secret, redirect_uris } = await getGoogleAppKeys();
this.myGoogleAuth = this.myGoogleAuth || new MyGoogleAuth(client_id, client_secret, redirect_uris[0]);
const googleCredentials = OAuth2UniversalSchema.parse(this.credential.key);
this.myGoogleAuth = new MyGoogleAuth(client_id, client_secret, redirect_uris[0]);
this.myGoogleAuth.setCredentials(googleCredentials);
return this.myGoogleAuth;
}
Expand Down Expand Up @@ -151,14 +153,18 @@ export default class GoogleCalendarService implements Calendar {
},
updateTokenObject: async (token) => {
this.myGoogleAuth.setCredentials(token);
await prisma.credential.update({

const { key } = await prisma.credential.update({
where: {
id: credential.id,
},
data: {
key: token,
},
});

// Update cached credential as well
this.credential.key = key;
},
});
this.oAuthManagerInstance = auth;
Expand Down

0 comments on commit 900e90c

Please sign in to comment.