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>
26 lines
1.2 KiB
TypeScript
26 lines
1.2 KiB
TypeScript
/**
|
|
* News consent lives in the church's Accounts once sign-in goes through it (3.0.0,
|
|
* docs/EVENTS-3.0-PLAN.md decision 7). An unsubscribe link or a WhatsApp STOP here turns news off
|
|
* there too (`people.newsOff`), so it's off for every product, and Accounts' next `user.updated`
|
|
* doesn't turn it back on here. Never fails the unsubscribe itself.
|
|
*/
|
|
import { accounts } from './client';
|
|
import { viaAccounts } from './mode';
|
|
|
|
/* eslint-disable @typescript-eslint/no-require-imports -- CommonJS */
|
|
const prisma = require('../config/db');
|
|
/* eslint-enable @typescript-eslint/no-require-imports */
|
|
|
|
export async function newsOffInAccounts(userId: string, channels: string[]): Promise<void> {
|
|
try {
|
|
if (!(await viaAccounts())) return;
|
|
const u = await prisma.user.findUnique({ where: { id: userId }, select: { accountId: true } });
|
|
if (!u?.accountId) return;
|
|
const both = channels.includes('email') && channels.includes('whatsapp');
|
|
const channel = both ? 'all' : channels.includes('whatsapp') ? 'whatsapp' : 'email';
|
|
await (await accounts()).request({ type: 'people.newsOff', actor: null, sub: u.accountId, channel });
|
|
} catch (e) {
|
|
console.warn('[accounts] news off not passed on:', (e as Error).message);
|
|
}
|
|
}
|