fix(auth): unify imported sessions with account gating

This commit is contained in:
jjbrunton committed 2026-08-08 16:53:55 +01:00
1 parent 654bbda457
commit ea92a1a92b
15 files changed
+123 -49

No files matched your search

+19 -3
View File
@@ -52,9 +52,25 @@ export function createLoginRouter(ctx: WebContext): Router {
return;
}
try {
const loggedIn = await browser.isSessionValid();
const username = loggedIn ? await browser.getAuthenticatedUsername() : null;
res.json({ ready: true, loggedIn, status: browser.getSessionState(), username });
const accountAuth = ctx.services.accountAuth;
const fullyAuthenticated = accountAuth
? await accountAuth.ensureFullyAuthenticated()
: await browser.isSessionValid();
if (fullyAuthenticated) {
const username = accountAuth?.getSnapshot().redditUsername
?? await browser.getAuthenticatedUsername();
res.json({ ready: true, loggedIn: true, status: 'authenticated', username });
return;
}
await browser.isSessionValid();
const browserState = browser.getSessionState();
res.json({
ready: true,
loggedIn: false,
status: browserState === 'unreachable' ? 'unreachable' : 'login-required',
username: null,
});
} catch (error) {
ctx.logger.error('Failed to check login status:', error);
res.status(500).json({ ready: true, loggedIn: false, error: 'check failed' });