Cross Events 3.0.0: sign-in through the church's Accounts

Settings -> Sign-in: check, move (everyone into Accounts with their password
hashes and authenticator apps, count/hash check, then switch) and undo for
14 days. Sign-in through auth-client with a one-time handoff to Events' own
token; staff roles stepped up to mfa; sign-out and back-channel logout;
user.updated/export/deleted; admin 2FA reset, unlock and profile changes via
Accounts; /login, /register, /forgot-password forward once moved; Events'
own sign-in endpoints answer SIGN_IN_MOVED. User.accountId, AccountsSignIn.

npm run test:accounts runs Events' code against the real Accounts app (11
tests); 5 new Jest tests. MIGRATING-TO-3.md, plan "Changes while building".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 14:10:30 +02:00
co-authored by Claude Opus 5.5
parent 56cbef1d9b
commit c627c61de1
49 changed files with 4094 additions and 245 deletions
+21
View File
@@ -48,6 +48,13 @@ const frontendUrl = () => (process.env.FRONTEND_URL || process.env.APP_BASE_URL
export async function sendActivationLink(user: { id: string; name?: string | null; email?: string | null; phoneNumber?: string | null }): Promise<void> {
const hasRealEmail = !!(user?.email && !user.email.endsWith('@guest.local'));
if (!hasRealEmail && !user?.phoneNumber) return;
// 3.0.0: once sign-in goes through the church's Accounts, Accounts makes (or finds) their account
// and emails them a link to choose a password; there's no Events activation any more.
if (hasRealEmail && (await (require('../accounts/mode') as typeof import('../accounts/mode')).viaAccounts())) {
ensureAccount(user as { id: string; name?: string | null; email: string; phoneNumber?: string | null })
.catch((e: any) => console.warn('[accounts] Could not make the account:', e?.message || e));
return;
}
try {
const token = uuidv4();
const expiresAt = new Date(Date.now() + 24 * 60 * 60 * 1000);
@@ -81,6 +88,20 @@ export async function sendActivationLink(user: { id: string; name?: string | nul
}
}
/** Asks Accounts for this person's account (people.ensure) and links it; they can then sign in. */
export async function ensureAccount(user: { id: string; name?: string | null; email: string; phoneNumber?: string | null }): Promise<string | null> {
const { accounts } = require('../accounts/client') as typeof import('../accounts/client');
const { siteUrl } = require('../feed/context') as typeof import('../feed/context');
const { phoneSchema } = require('@crosscode/contracts') as typeof import('@crosscode/contracts');
const phone = user.phoneNumber && phoneSchema.safeParse(user.phoneNumber).success ? user.phoneNumber : null;
const r = await (await accounts()).request<{ sub: string; created: boolean }>({
type: 'people.ensure', actor: null, name: (user.name || user.email).slice(0, 200), email: user.email.toLowerCase(), phone, returnUrl: `${(await siteUrl()).replace(/\/+$/, '')}/`,
});
const other = await prisma.user.findUnique({ where: { accountId: r.sub }, select: { id: true } });
if (!other) await prisma.user.update({ where: { id: user.id }, data: { accountId: r.sub, isActive: true } });
return r.sub;
}
// Fire-and-forget: a login notice with the approximate place it came from.
async function sendLoginNotification(user: any, info: RequestInfo): Promise<void> {
try {