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
@@ -4,6 +4,8 @@ import React, { createContext, useCallback, useContext, useEffect, useMemo, useS
import { ApiError } from "@/lib/api";
import { AuthResponse, AuthUser, TwoFactorChallenge, clearToken, getDeviceToken, getToken, saveDeviceToken, saveToken } from "@/lib/auth";
import { apiV2, type V2Result, apiV2Data } from "@/lib/apiV2";
import { API_BASE } from "@/lib/api";
import { fetchAuthMode } from "@/lib/signIn";
// A v2 "signed_in" answer as the session the app keeps (the user's fields plus the token).
type V2Session = Extract<V2Result<"/auth/login", "post">["data"], { status: "signed_in" }>;
@@ -142,10 +144,21 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
}, []);
const logout = useCallback(() => {
const t = getToken();
clearToken();
cacheUser(null);
setToken(null);
setUser(null);
// 3.0.0: signed in through the church's Accounts, signing out here signs out there too (and of
// the church's other products), then comes back to this site's home page.
if (t) {
fetchAuthMode()
.then((m) => (m === "accounts"
? fetch(`${API_BASE}/api/auth/signout`, { method: "POST", headers: { Authorization: `Bearer ${t}`, "Content-Type": "application/json" }, body: "{}" }).then((r) => r.json())
: null))
.then((j: { data?: { url?: string | null } } | null) => { if (j?.data?.url) window.location.assign(j.data.url); })
.catch(() => { /* signed out here either way */ });
}
}, []);
// Some endpoints (profile update, password change, session revocation) issue a