refactor: Pass app data within the constructor of an app

This commit is contained in:
Faruk AYDIN
2022-02-27 18:22:17 +03:00
committed by Ali BARIN
parent 003213d223
commit c864a1062d
24 changed files with 216 additions and 174 deletions

View File

@@ -1,31 +1,33 @@
import TwilioApi from 'twilio';
import App from '../../models/app';
export default class Authentication {
client: any
connectionData: any
appData: any
client: any;
connectionData: any;
appData: any;
constructor(connectionData: any) {
this.client = TwilioApi(connectionData.accountSid, connectionData.authToken);
constructor(appData: any, connectionData: any) {
this.client = TwilioApi(
connectionData.accountSid,
connectionData.authToken
);
this.connectionData = connectionData;
this.appData = App.findOneByKey('twilio');
this.appData = appData;
}
async verifyCredentials() {
await this.verify();
return {
screenName: this.connectionData.accountSid
}
screenName: this.connectionData.accountSid,
};
}
async verify() {
try {
await this.client.keys.list({ limit: 1 })
await this.client.keys.list({ limit: 1 });
return true;
} catch(error) {
} catch (error) {
// Test credentials throw HTTP 403 and thus, we need to have an exception.
return error?.status === 403;
}