Skip to content

Commit

Permalink
chore(auth): split files
Browse files Browse the repository at this point in the history
  • Loading branch information
louisgrasset committed Nov 22, 2023
1 parent 63fc36c commit ff89381
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
TOUITOMAMOUT_VERSION,
TWITTER_HANDLE,
} from "../constants.js";
import { handleTwitterAuth } from "../helpers/auth/auth.js";
import { handleTwitterAuth } from "../helpers/auth/index.js";
import { createCacheFile } from "../helpers/cache/create-cache.js";
import { getCachedPosts } from "../helpers/cache/get-cached-posts.js";
import { runMigrations } from "../helpers/cache/run-migrations.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,9 @@ import { Scraper } from "@the-convocation/twitter-scraper";
import ora from "ora";

import { TWITTER_PASSWORD, TWITTER_USERNAME } from "../../constants.js";
import { getCookies } from "../cookies/get-cookies.js";
import { saveCookies } from "../cookies/save-cookies.js";
import { TouitomamoutError } from "../error.js";
import { oraPrefixer } from "../logs/index.js";

const restorePreviousSession = async (client: Scraper): Promise<void> => {
try {
const cookies = await getCookies();
if (cookies) {
await client.setCookies(cookies);
} else {
throw new Error("Unable to restore cookies");
}
} catch (err) {
console.log(
TouitomamoutError(err as string, [
"Logging in with credentials instead.",
]),
);
}
};
import { restorePreviousSession } from "./restore-previous-session.js";

export const handleTwitterAuth = async (client: Scraper) => {
const log = ora({
Expand Down
1 change: 1 addition & 0 deletions src/helpers/auth/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./handle-twitter-auth.js";
23 changes: 23 additions & 0 deletions src/helpers/auth/restore-previous-session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Scraper } from "@the-convocation/twitter-scraper";

import { getCookies } from "../cookies/get-cookies.js";
import { TouitomamoutError } from "../error.js";

export const restorePreviousSession = async (
client: Scraper,
): Promise<void> => {
try {
const cookies = await getCookies();
if (cookies) {
await client.setCookies(cookies);
} else {
throw new Error("Unable to restore cookies");
}
} catch (err) {
console.log(
TouitomamoutError(err as string, [
"Logging in with credentials instead.",
]),
);
}
};

0 comments on commit ff89381

Please sign in to comment.