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

+14 -3
View File
@@ -18,13 +18,23 @@ export function createLoginRouter(ctx: WebContext): Router {
router.get('/login/status', async (_req, res) => {
const browser = ctx.services.browser;
if (!browser) {
const accountAuth = ctx.services.accountAuth;
if (!browser || !accountAuth) {
res.status(503).json({ ready: false, error: 'browser not initialised' });
return;
}
try {
const loggedIn = await browser.isSessionValid();
res.json({ ready: true, loggedIn, status: browser.getSessionState() });
const loggedIn = await accountAuth.ensureFullyAuthenticated();
const browserState = browser.getSessionState();
res.json({
ready: true,
loggedIn,
status: loggedIn
? 'authenticated'
: browserState === 'unreachable'
? 'unreachable'
: 'login-required',
});
} catch (error) {
ctx.logger.error('Failed to check login status:', error);
res.status(500).json({ ready: true, loggedIn: false, error: 'check failed' });
@@ -40,6 +50,7 @@ export function createLoginRouter(ctx: WebContext): Router {
return;
}
try {
ctx.services.accountAuth?.invalidate('Interactive Reddit login requested');
const page = await browser.getPage();
await page.bringToFront().catch(() => undefined);
await page.goto('https://www.reddit.com/login', { waitUntil: 'domcontentloaded' });