Mode2Test/AuthAndToken: assume tokens always fresh with background refresh; fix jobs API to use correct collection; align Home UI to Mode1 (exact fields, styling, strict Active dot); add full-field IndexedDB cache w/ pagination; remove progress bar; dev TLS bypass; rebuild bundles

This commit is contained in:
2026-01-17 20:20:24 +00:00
parent eed8552282
commit d77fa4b817
21 changed files with 5964 additions and 205 deletions
+14 -14
View File
@@ -1,9 +1,10 @@
import { Hono } from 'hono';
import type { Context } from 'hono';
import { getTokens, saveTokens, clearTokens, hasValidPbToken } from './token-service';
import { tokenService } from './token-service';
// Authentication API routes
// Endpoints for frontend to check auth status, get tokens, logout
// Depends on: tokenService singleton (centralized token management)
export function createAuthRoutes(): Hono {
const router = new Hono();
@@ -11,11 +12,13 @@ export function createAuthRoutes(): Hono {
// PERMANENT: Check if user is authenticated
// Returns current auth status and which tokens are available
router.get('/status', async (c: Context) => {
const hasValid = await hasValidPbToken();
const tokens = await tokenService.getTokens();
const hasToken = !!tokens?.pbToken;
return c.json({
authenticated: hasValid,
pbTokenValid: hasValid,
message: hasValid ? 'User authenticated' : 'User not authenticated'
authenticated: hasToken,
pbTokenValid: hasToken,
assumedFresh: hasToken,
message: hasToken ? 'Assuming tokens are valid (auto-refresh running)' : 'No PB token yet; login once'
});
});
@@ -23,17 +26,14 @@ export function createAuthRoutes(): Hono {
// Frontend/backend can call this to get fresh token state
// Only returns tokens if PB token is valid (auth required)
router.get('/tokens', async (c: Context) => {
const hasValid = await hasValidPbToken();
if (!hasValid) {
return c.json({ error: 'Not authenticated' }, 401);
}
const tokens = await getTokens();
const tokens = await tokenService.getTokens();
return c.json({
pbToken: tokens?.pbToken || null,
graphToken: tokens?.graphToken || null,
pbTokenExpiry: tokens?.pbTokenExpiry || null,
graphTokenExpiry: tokens?.graphTokenExpiry || null
graphTokenExpiry: tokens?.graphTokenExpiry || null,
lastRefresh: tokens?.lastRefresh || null,
assumedFresh: !!tokens?.pbToken
});
});
@@ -50,7 +50,7 @@ export function createAuthRoutes(): Hono {
return c.json({ error: 'Missing pbToken' }, 400);
}
await saveTokens(pbToken, graphToken);
await tokenService.saveTokens(pbToken, graphToken);
return c.json({
success: true,
message: 'Login successful',
@@ -66,7 +66,7 @@ export function createAuthRoutes(): Hono {
// Called when user clicks logout
router.post('/logout', async (c: Context) => {
try {
await clearTokens();
await tokenService.clearTokens();
return c.json({
success: true,
message: 'Logged out',