Skip to content

Commit

Permalink
chore: throw error for empty creds
Browse files Browse the repository at this point in the history
  • Loading branch information
tiwarishubham635 committed Dec 4, 2024
1 parent baa0875 commit 8ae3be5
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/base/BaseTwilio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,11 @@ namespace Twilio {
this.username =
username ??
this.env?.TWILIO_ACCOUNT_SID ??
process.env.TWILIO_ACCOUNT_SID ??
(() => {
throw new Error("username is required");
})();
process.env.TWILIO_ACCOUNT_SID;
this.password =
password ??
this.env?.TWILIO_AUTH_TOKEN ??
process.env.TWILIO_AUTH_TOKEN ??
(() => {
throw new Error("password is required");
})();
process.env.TWILIO_AUTH_TOKEN;
this.accountSid = "";
this.setAccountSid(this.opts?.accountSid || this.username);
this.invalidateOAuth();
Expand Down Expand Up @@ -156,8 +150,8 @@ namespace Twilio {
}
}

setAccountSid(accountSid: string) {
this.accountSid = accountSid;
setAccountSid(accountSid?: string) {
this.accountSid = accountSid || "";

if (this.accountSid && !this.accountSid?.startsWith("AC")) {
const apiKeyMsg = this.accountSid?.startsWith("SK")
Expand Down Expand Up @@ -228,6 +222,20 @@ namespace Twilio {
const authStrategy =
opts.authStrategy || this.credentialProvider?.toAuthStrategy();

if (!authStrategy) {
if (!username) {
(() => {
throw new Error("username is required");
})();
}

if (!password) {
(() => {
throw new Error("password is required");
})();
}
}

const headers = opts.headers || {};

const pkgVersion = moduleInfo.version;
Expand Down

0 comments on commit 8ae3be5

Please sign in to comment.