Gate bot logic on full account authentication

This commit is contained in:
jjbrunton committed 2026-08-08 16:01:06 +01:00
1 parent 4db6de8bf5
commit 2fd92bf82c
22 files changed
+635 -65

No files matched your search

+18 -5
View File
@@ -112,6 +112,15 @@ export class BrowserClient {
return this.sessionState;
}
async getAuthenticatedUsername(): Promise<string | null> {
try {
const page = await this.getPage();
return await this.readAuthenticatedUsername(page);
} catch {
return null;
}
}
async close(): Promise<void> {
if (this.connectedBrowser) {
this.logger.info('Closing Google Chrome connection');
@@ -185,19 +194,23 @@ export class BrowserClient {
}
private async isLoggedInViaApi(page: Page): Promise<boolean> {
return (await this.readAuthenticatedUsername(page)) !== null;
}
private async readAuthenticatedUsername(page: Page): Promise<string | null> {
try {
return await page.evaluate(async () => {
try {
const res = await fetch('https://www.reddit.com/api/me.json', { credentials: 'include' });
if (!res.ok) return false;
const data = await res.json();
return Boolean(data && data.name);
if (!res.ok) return null;
const data = await res.json() as { name?: unknown };
return typeof data.name === 'string' && data.name ? data.name : null;
} catch {
return false;
return null;
}
});
} catch {
return false;
return null;
}
}