Accounts 1.1.0: moving Events' users in, people.* requests, new recovery codes

POST /api/accounts/v1/requests (crosscode.identity-request/1): import.* keeps
each person's Events id as sub, password hash and authenticator secret
(sealed in transit), consent, notices and lockout; linked when the email
already has an account. people.* for product admins, limited to people the
product knows. New recovery codes after the first 2FA sign-in for people
moved in with 2FA. screen=signup. auth-client: request(), seal(), signUp.
8 new tests (47 in all).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 13:40:15 +02:00
co-authored by Claude Opus 5.5
parent 08fef930c1
commit 733992e917
19 changed files with 834 additions and 39 deletions
+13 -2
View File
@@ -18,7 +18,7 @@ import type { Account, PendingSignIn } from '../generated/prisma/client.js';
import {
codeMatches, emailProblem, isLocked, maskedTarget, normaliseEmail, normalisePhone, sendCode, setNewsConsent, signInFailed, signInSucceeded, CODE_MINUTES,
} from '../accounts/service.js';
import { accessAfterTwoFactor, confirmTwoFactorSetup, startTwoFactorSetup, useRecoveryCode, verifyTotp } from '../accounts/twoFactor.js';
import { accessAfterTwoFactor, confirmTwoFactorSetup, replaceRecoveryCodes, startTwoFactorSetup, useRecoveryCode, verifyTotp } from '../accounts/twoFactor.js';
import { loginEvent } from '../lib/audit.js';
import { dummyHash, hashPassword, needsRehash, passwordProblem, verifyPassword } from '../lib/passwords.js';
import { accept as acceptNotice, currentNotice } from '../privacy/notice.js';
@@ -94,6 +94,8 @@ export async function describe(ctx: Ctx, details: Details, pending: PendingSignI
signupEnabled: await ctx.settings.bool('signup_enabled', true),
mfaRequested: mfaRequested(details),
loginHint: typeof details.params.login_hint === 'string' ? details.params.login_hint : null,
// 1.1.0: a product's "Create an account" link opens on sign-up (`screen=signup`).
screen: details.params.screen === 'signup' ? 'signup' : 'signin',
};
if (stage === 'password' || stage === 'done') return base;
const a = await account(ctx, pending);
@@ -209,7 +211,16 @@ export async function twoFactor(ctx: Ctx, pending: PendingSignIn, input: { code?
} else {
await checkCode(ctx, pending, input.code);
}
return save(ctx, pending, { amr: accessAfterTwoFactor(pending.amr), codeHash: null, codeSentAt: null, attempts: 0 });
const next = await save(ctx, pending, { amr: accessAfterTwoFactor(pending.amr), codeHash: null, codeSentAt: null, attempts: 0 });
// Moved in from a product without its recovery codes (EVENTS-3.0-PLAN decision 2): new ones now,
// shown once on the next page.
if (a.recoveryCodesNeeded) {
const recoveryCodes = await replaceRecoveryCodes(ctx, a.id);
await ctx.db.account.update({ where: { id: a.id }, data: { recoveryCodesNeeded: false } });
await loginEvent(ctx, a.id, 'recovery_codes_replaced', req, { detail: { by: 'move' } });
return { pending: next, recoveryCodes };
}
return { pending: next, recoveryCodes: null as string[] | null };
}
export async function setupStart(ctx: Ctx, pending: PendingSignIn, method: unknown) {