Skip to content

Commit

Permalink
Merge pull request #1330 from ChristopherTrimboli/chore/twitter-cookies
Browse files Browse the repository at this point in the history
fix: Twitter login notifications, incorrect cookie management.
  • Loading branch information
monilpat authored Dec 23, 2024
2 parents 2a5cc4d + 16c8577 commit b1a6b9d
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/client-twitter/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,25 @@ export class ClientBase extends EventEmitter {
elizaLogger.log("Waiting for Twitter login");
while (retries > 0) {
try {
await this.twitterClient.login(
username,
password,
email,
twitter2faSecret
);
if (await this.twitterClient.isLoggedIn()) {
if (await this.twitterClient.isLoggedIn()) { // cookies are valid, no login required
elizaLogger.info("Successfully logged in.");
if (!cachedCookies) {
break;
} else {
await this.twitterClient.login(
username,
password,
email,
twitter2faSecret
);
if (await this.twitterClient.isLoggedIn()) { // fresh login, store new cookies
elizaLogger.info("Successfully logged in.");
elizaLogger.info("Caching cookies");
await this.cacheCookies(
username,
await this.twitterClient.getCookies()
);
break;
}
break;
}
} catch (error) {
elizaLogger.error(`Login attempt failed: ${error.message}`);
Expand Down

0 comments on commit b1a6b9d

Please sign in to comment.