Skip to content

Commit

Permalink
Ensure token validity check happens correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinsandilya committed Feb 23, 2023
1 parent f3a397f commit da13b67
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/app-store/zohocrm/lib/CalendarService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,13 @@ export default class ZohoCrmCalendarService implements Calendar {
if (!this.client_secret)
throw new HttpError({ statusCode: 400, message: "Zoho CRM client_secret missing." });
const credentialKey: any = credential.key;
const isTokenValid = (token: any) =>
token &&
token.token_type &&
token.access_token &&
token.expiryDate &&
(token.expires_in || token.expiryDate) < Date.now();
const isTokenValid = (token: any) => {
const isValid = token && token.access_token && token.expiryDate && token.expiryDate < Date.now();
if (isValid) {
this.accessToken = token.access_token;
}
return isValid;
};

const refreshAccessToken = async (credentialKey: any) => {
try {
Expand Down Expand Up @@ -189,8 +190,7 @@ export default class ZohoCrmCalendarService implements Calendar {
};

return {
getToken: () =>
isTokenValid(credential.key) ? Promise.resolve([]) : refreshAccessToken(credentialKey),
getToken: () => (isTokenValid(credentialKey) ? Promise.resolve([]) : refreshAccessToken(credentialKey)),
};
};

Expand Down

0 comments on commit da13b67

Please sign in to comment.