Attempt to re-authenticate on auth refresh error

This commit is contained in:
Matt Low 2021-03-13 14:51:32 -07:00
parent 2668f4d814
commit bc7500ce3e

View File

@ -68,16 +68,24 @@ async function initRingCentralSDK() {
clientId: process.env.RC_APP_KEY,
clientSecret: process.env.RC_APP_SECRET,
});
const login = () =>
sdk.login({
username: process.env.RC_LOGIN_USERNAME,
extension: process.env.RC_LOGIN_EXT,
password: process.env.RC_LOGIN_PASSWORD,
});
const platform = sdk.platform();
platform.on(platform.events.refreshError, (err) => {
console.error(err);
});
await sdk.login({
username: process.env.RC_LOGIN_USERNAME,
extension: process.env.RC_LOGIN_EXT,
password: process.env.RC_LOGIN_PASSWORD,
platform.on(platform.events.refreshError, async (err) => {
console.error("Refresh token error:", err);
await login();
console.log("RingCentral re-authentication successful.");
});
await login();
console.log("Authenticated to RingCentral.");
return sdk;
}