Events 3.5.0, contracts 1.13.0, agent 1.3.1: demo data keeps the Accounts link; sign-in health for the Hub
- Events: loading demo data emptied ProductLink but kept auth_mode, so a site in Accounts mode had no link and nobody could sign in (ACCOUNTS_UNAVAILABLE on events-demo). set-demo.js keeps ProductLink and LinkNonce; a site in Accounts mode without a link reconnects at its next heartbeat; sign-in failures are kept and sent in the heartbeat (stats.signIn). - Contracts 1.13.0: stats.signIn in the Cross Events heartbeat. - Agent 1.3.1: 1.3.0 reported itself as 1.2.0 (AGENT_VERSION not bumped). - What's New notes for Events 3.4.0 / 3.5.0 and Accounts 1.4.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,12 +7,16 @@
|
||||
import { connectTo } from '../links/connect';
|
||||
import { linkedProducts } from '../links/store';
|
||||
import { accountsLink } from './client';
|
||||
import { getSetting, setSetting } from './mode';
|
||||
import { getSetting, setSetting, viaAccounts } from './mode';
|
||||
|
||||
export const AUTO_KEY = 'accounts_auto_connected';
|
||||
|
||||
export async function connectAccountsIfListed(now = new Date()): Promise<'connected' | 'skipped'> {
|
||||
if (await getSetting(AUTO_KEY)) return 'skipped';
|
||||
// 3.5.0: a site that signs in through Accounts but has lost its link (before 3.5.0, loading demo
|
||||
// data deleted it) can't sign anyone in, so it reconnects whatever was done before. A site on its
|
||||
// own sign-in keeps an admin's Disconnect.
|
||||
const stranded = (await viaAccounts()) && !(await accountsLink());
|
||||
if ((await getSetting(AUTO_KEY)) && !stranded) return 'skipped';
|
||||
if (await accountsLink()) {
|
||||
await setSetting(AUTO_KEY, now.toISOString());
|
||||
return 'skipped';
|
||||
|
||||
@@ -20,6 +20,7 @@ import { siteUrl } from '../feed/context';
|
||||
import { accounts, AccountsUnavailable } from './client';
|
||||
import { viaAccounts } from './mode';
|
||||
import { handleAccountsCall } from './calls';
|
||||
import { clearSignInError, recordSignInError } from './status';
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-require-imports -- CommonJS */
|
||||
const prisma = require('../config/db');
|
||||
@@ -144,7 +145,10 @@ async function startSignIn(req: Request, res: Response) {
|
||||
return res.redirect(303, url);
|
||||
} catch (e) {
|
||||
console.warn('[accounts] sign-in could not start:', (e as Error).message);
|
||||
return problem(res, e instanceof AccountsUnavailable ? 'ACCOUNTS_UNAVAILABLE' : 'START_FAILED', returnTo);
|
||||
const failed = e instanceof AccountsUnavailable ? 'ACCOUNTS_UNAVAILABLE' : 'START_FAILED';
|
||||
// 3.5.0: the reason goes to the Hub with the next heartbeat (the page only says "try again").
|
||||
await recordSignInError(failed, (e as Error).message);
|
||||
return problem(res, failed, returnTo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +162,8 @@ async function callback(req: Request, res: Response) {
|
||||
let auth;
|
||||
try {
|
||||
auth = await accounts();
|
||||
} catch {
|
||||
} catch (e) {
|
||||
await recordSignInError('ACCOUNTS_UNAVAILABLE', (e as Error).message);
|
||||
return problem(res, 'ACCOUNTS_UNAVAILABLE');
|
||||
}
|
||||
let signed;
|
||||
@@ -168,8 +173,10 @@ async function callback(req: Request, res: Response) {
|
||||
} catch (e) {
|
||||
const code = (e as { code?: string }).code;
|
||||
console.warn('[accounts] sign-in could not finish:', (e as Error).message);
|
||||
if (code !== 'NO_PENDING') await recordSignInError('FINISH_FAILED', (e as Error).message);
|
||||
return problem(res, code === 'NO_PENDING' ? 'EXPIRED' : 'FINISH_FAILED');
|
||||
}
|
||||
await clearSignInError();
|
||||
const { claims, returnTo, idToken } = signed;
|
||||
|
||||
const found = await userForClaims(claims);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* How people sign in here, for the Hub (3.5.0, heartbeat `stats.signIn`, contracts 1.13.0): the
|
||||
* mode, the Accounts this site is linked to, and the last sign-in that failed to start or finish.
|
||||
* A site in `accounts` mode without a link can't sign anyone in; the Hub raises an alert for it.
|
||||
*/
|
||||
import { accountsLink } from './client';
|
||||
import { authMode, getSetting, setSetting } from './mode';
|
||||
|
||||
export const LAST_ERROR_KEY = 'accounts_last_signin_error';
|
||||
|
||||
type LastError = { at: string; code: string; message: string };
|
||||
|
||||
/** Keeps the last failure (a code and a sentence; never tokens or cookies). */
|
||||
export async function recordSignInError(code: string, message: string, now = new Date()): Promise<void> {
|
||||
const value: LastError = { at: now.toISOString(), code: code.slice(0, 60), message: message.replace(/\s+/g, ' ').slice(0, 500) };
|
||||
await setSetting(LAST_ERROR_KEY, JSON.stringify(value)).catch(() => {});
|
||||
}
|
||||
|
||||
/** A sign-in that worked clears it. */
|
||||
export async function clearSignInError(): Promise<void> {
|
||||
if (await getSetting(LAST_ERROR_KEY).catch(() => null)) await setSetting(LAST_ERROR_KEY, null).catch(() => {});
|
||||
}
|
||||
|
||||
export async function signInStatus(): Promise<{ mode: 'local' | 'accounts'; accounts: { installId: string; url: string } | null; lastError: LastError | null }> {
|
||||
const [mode, link, raw] = await Promise.all([authMode(), accountsLink(), getSetting(LAST_ERROR_KEY).catch(() => null)]);
|
||||
let lastError: LastError | null = null;
|
||||
try {
|
||||
const parsed = raw ? JSON.parse(raw) : null;
|
||||
if (parsed && typeof parsed.at === 'string' && typeof parsed.code === 'string' && typeof parsed.message === 'string') lastError = parsed;
|
||||
} catch { /* an unreadable value is no error */ }
|
||||
return { mode, accounts: link ? { installId: link.installId, url: link.url } : null, lastError };
|
||||
}
|
||||
@@ -145,10 +145,13 @@ async function stats(now = new Date()) {
|
||||
const live = await liveNow(now).catch(() => undefined);
|
||||
const campusesOn = await campusesEnabled().catch(() => false);
|
||||
const campusCount = campusesOn ? await prisma.campus.count({ where: { archivedAt: null } }) : 0;
|
||||
// 3.5.0: how people sign in (the Hub flags a site in Accounts mode without a link, or failing).
|
||||
const signIn = await require('../accounts/status').signInStatus().catch(() => undefined);
|
||||
return {
|
||||
users,
|
||||
events: { active: activeEvents, upcoming: upcomingEvents, total: totalEvents },
|
||||
...(live ? { live } : {}),
|
||||
...(signIn ? { signIn } : {}),
|
||||
registrations: { last30d: regs30, total: regsTotal },
|
||||
tickets: { last30d: tickets30, total: ticketsTotal },
|
||||
checkIns: { last30d: checkIns30 },
|
||||
|
||||
Reference in New Issue
Block a user