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
@@ -72240,6 +72240,950 @@
}
}
}
},
"/auth/mode": {
"get": {
"tags": [
"Accounts"
],
"summary": "Where people sign in",
"description": "`accounts`: send people to `GET /api/auth/signin?returnTo=<this page>` (the church's Accounts). `local`: Cross Events' own sign-in.\n\n**Who:** Anyone.",
"operationId": "getAuthMode",
"parameters": [],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"mode": {
"type": "string",
"enum": [
"local",
"accounts"
]
},
"signInUrl": {
"type": "string"
},
"accountUrl": {
"description": "With `accounts`: the church account page (profile, password, two-step sign-in, privacy)",
"type": [
"string",
"null"
]
}
},
"required": [
"mode",
"signInUrl",
"accountUrl"
],
"additionalProperties": false
}
},
"required": [
"data"
],
"additionalProperties": false
}
}
}
}
}
}
},
"/settings/sign-in": {
"get": {
"tags": [
"Accounts"
],
"summary": "Sign-in: where it is and the move to Accounts",
"description": "**Who:** Admins only.",
"operationId": "getSettingsSign-in",
"security": [
{
"bearerAuth": []
}
],
"parameters": [],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"mode": {
"type": "string",
"enum": [
"local",
"accounts"
],
"description": "local: Cross Events' own sign-in; accounts: through the church's Accounts"
},
"accountsConnected": {
"type": "boolean"
},
"accountsUrl": {
"type": [
"string",
"null"
]
},
"movedAt": {
"type": [
"string",
"null"
]
},
"undoUntil": {
"description": "Undo is possible until then (14 days after the move)",
"type": [
"string",
"null"
]
},
"secretsCleared": {
"type": "boolean",
"description": "The old passwords have been removed (Undo is no longer possible)"
},
"running": {
"type": "boolean"
},
"report": {
"anyOf": [
{},
{
"type": "null"
}
]
}
},
"required": [
"mode",
"accountsConnected",
"accountsUrl",
"movedAt",
"undoUntil",
"secretsCleared",
"running",
"report"
],
"additionalProperties": false
}
},
"required": [
"data"
],
"additionalProperties": false
}
}
}
},
"401": {
"description": "Not signed in (UNAUTHENTICATED)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"403": {
"description": "Not allowed for this role (FORBIDDEN)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
},
"/settings/sign-in/check": {
"post": {
"tags": [
"Accounts"
],
"summary": "Check the move to Accounts (nothing changes)",
"description": "Who would move, who already has an account (they're linked to it), who is skipped (guests, deleted) and anything that would stop the move.\n\n**Who:** Admins only.",
"operationId": "postSettingsSign-inCheck",
"security": [
{
"bearerAuth": []
}
],
"parameters": [],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"accountsVersion": {
"type": "string"
},
"toMove": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991
},
"wouldCreate": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991
},
"wouldLink": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string"
}
},
"required": [
"name",
"email"
],
"additionalProperties": false
}
},
"refused": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"reason": {
"type": "string"
}
},
"required": [
"name",
"email",
"reason"
],
"additionalProperties": false
}
},
"skipped": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991
},
"admins": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"id": {
"type": "string"
}
},
"required": [
"name",
"email",
"id"
],
"additionalProperties": false
}
},
"noticeConflict": {
"anyOf": [
{
"type": "object",
"properties": {
"accountsVersions": {
"type": "array",
"items": {
"type": "number"
}
},
"eventsVersions": {
"type": "array",
"items": {
"type": "number"
}
}
},
"required": [
"accountsVersions",
"eventsVersions"
],
"additionalProperties": false
},
{
"type": "null"
}
]
},
"withTwoFactor": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991
}
},
"required": [
"accountsVersion",
"toMove",
"wouldCreate",
"wouldLink",
"refused",
"skipped",
"admins",
"noticeConflict",
"withTwoFactor"
],
"additionalProperties": false
}
},
"required": [
"data"
],
"additionalProperties": false
}
}
}
},
"401": {
"description": "Not signed in (UNAUTHENTICATED)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"403": {
"description": "Not allowed for this role (FORBIDDEN)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
},
"/settings/sign-in/move": {
"post": {
"tags": [
"Accounts"
],
"summary": "Move sign-in to Accounts",
"description": "Copies everyone into the church's Accounts with their passwords and authenticator apps, checks the count, then switches. Nothing switches if anything fails, and it can be run again. Undo for 14 days.\n\n**Who:** Admins only.",
"operationId": "postSettingsSign-inMove",
"security": [
{
"bearerAuth": []
}
],
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"adminIds": {
"maxItems": 500,
"type": "array",
"items": {
"type": "string",
"format": "uuid",
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
},
"description": "Events admins who also become Accounts admins"
},
"keepAccountsNotices": {
"description": "When Accounts has its own privacy notice: keep it (everyone accepts it at their next sign-in) instead of Events'",
"type": "boolean"
}
},
"required": [
"adminIds"
]
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"mode": {
"type": "string",
"enum": [
"local",
"accounts"
],
"description": "local: Cross Events' own sign-in; accounts: through the church's Accounts"
},
"accountsConnected": {
"type": "boolean"
},
"accountsUrl": {
"type": [
"string",
"null"
]
},
"movedAt": {
"type": [
"string",
"null"
]
},
"undoUntil": {
"description": "Undo is possible until then (14 days after the move)",
"type": [
"string",
"null"
]
},
"secretsCleared": {
"type": "boolean",
"description": "The old passwords have been removed (Undo is no longer possible)"
},
"running": {
"type": "boolean"
},
"report": {
"anyOf": [
{},
{
"type": "null"
}
]
}
},
"required": [
"mode",
"accountsConnected",
"accountsUrl",
"movedAt",
"undoUntil",
"secretsCleared",
"running",
"report"
],
"additionalProperties": false
}
},
"required": [
"data"
],
"additionalProperties": false
}
}
}
},
"400": {
"description": "Validation failed (VALIDATION_FAILED)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"401": {
"description": "Not signed in (UNAUTHENTICATED)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"403": {
"description": "Not allowed for this role (FORBIDDEN)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
},
"/settings/sign-in/undo": {
"post": {
"tags": [
"Accounts"
],
"summary": "Undo the move (back to Cross Events' own sign-in)",
"description": "Within 14 days of the move. People sign in with the password they had at the move; changes made in Accounts since then don't come back here.\n\n**Who:** Admins only.",
"operationId": "postSettingsSign-inUndo",
"security": [
{
"bearerAuth": []
}
],
"parameters": [],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"mode": {
"type": "string",
"enum": [
"local",
"accounts"
],
"description": "local: Cross Events' own sign-in; accounts: through the church's Accounts"
},
"accountsConnected": {
"type": "boolean"
},
"accountsUrl": {
"type": [
"string",
"null"
]
},
"movedAt": {
"type": [
"string",
"null"
]
},
"undoUntil": {
"description": "Undo is possible until then (14 days after the move)",
"type": [
"string",
"null"
]
},
"secretsCleared": {
"type": "boolean",
"description": "The old passwords have been removed (Undo is no longer possible)"
},
"running": {
"type": "boolean"
},
"report": {
"anyOf": [
{},
{
"type": "null"
}
]
}
},
"required": [
"mode",
"accountsConnected",
"accountsUrl",
"movedAt",
"undoUntil",
"secretsCleared",
"running",
"report"
],
"additionalProperties": false
}
},
"required": [
"data"
],
"additionalProperties": false
}
}
}
},
"401": {
"description": "Not signed in (UNAUTHENTICATED)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"403": {
"description": "Not allowed for this role (FORBIDDEN)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
},
"/users/{id}/account/reset-two-factor": {
"post": {
"tags": [
"Accounts"
],
"summary": "Reset someone's two-step sign-in (in Accounts)",
"description": "They set it up again at their next sign-in, and are signed out everywhere.\n\n**Who:** Admins only.",
"operationId": "postUsersIdAccountReset-two-factor",
"security": [
{
"bearerAuth": []
}
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"description": "The id",
"schema": {
"type": "string",
"format": "uuid",
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"ok": {
"type": "boolean",
"const": true
}
},
"required": [
"ok"
],
"additionalProperties": false
}
},
"required": [
"data"
],
"additionalProperties": false
}
}
}
},
"400": {
"description": "Validation failed (VALIDATION_FAILED)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"401": {
"description": "Not signed in (UNAUTHENTICATED)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"403": {
"description": "Not allowed for this role (FORBIDDEN)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"404": {
"description": "Not found (NOT_FOUND)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
},
"/users/{id}/account/unlock": {
"post": {
"tags": [
"Accounts"
],
"summary": "Unlock someone after too many wrong passwords (in Accounts)",
"description": "**Who:** Admins only.",
"operationId": "postUsersIdAccountUnlock",
"security": [
{
"bearerAuth": []
}
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"description": "The id",
"schema": {
"type": "string",
"format": "uuid",
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"ok": {
"type": "boolean",
"const": true
}
},
"required": [
"ok"
],
"additionalProperties": false
}
},
"required": [
"data"
],
"additionalProperties": false
}
}
}
},
"400": {
"description": "Validation failed (VALIDATION_FAILED)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"401": {
"description": "Not signed in (UNAUTHENTICATED)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"403": {
"description": "Not allowed for this role (FORBIDDEN)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"404": {
"description": "Not found (NOT_FOUND)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
},
"/users/{id}/account/active": {
"post": {
"tags": [
"Accounts"
],
"summary": "Turn someone's church account off or on everywhere (in Accounts)",
"description": "Off signs them out of every product of the church. To only stop them using Cross Events, deactivate them here instead.\n\n**Who:** Admins only.",
"operationId": "postUsersIdAccountActive",
"security": [
{
"bearerAuth": []
}
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"description": "The id",
"schema": {
"type": "string",
"format": "uuid",
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"active": {
"type": "boolean"
}
},
"required": [
"active"
]
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"ok": {
"type": "boolean",
"const": true
}
},
"required": [
"ok"
],
"additionalProperties": false
}
},
"required": [
"data"
],
"additionalProperties": false
}
}
}
},
"400": {
"description": "Validation failed (VALIDATION_FAILED)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"401": {
"description": "Not signed in (UNAUTHENTICATED)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"403": {
"description": "Not allowed for this role (FORBIDDEN)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"404": {
"description": "Not found (NOT_FOUND)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
}
},
"components": {
+645
View File
@@ -7498,6 +7498,178 @@ export interface paths {
patch?: never;
trace?: never;
};
"/auth/mode": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/**
* Where people sign in
* @description `accounts`: send people to `GET /api/auth/signin?returnTo=<this page>` (the church's Accounts). `local`: Cross Events' own sign-in.
*
* **Who:** Anyone.
*/
get: operations["getAuthMode"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/settings/sign-in": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/**
* Sign-in: where it is and the move to Accounts
* @description **Who:** Admins only.
*/
get: operations["getSettingsSign-in"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/settings/sign-in/check": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put?: never;
/**
* Check the move to Accounts (nothing changes)
* @description Who would move, who already has an account (they're linked to it), who is skipped (guests, deleted) and anything that would stop the move.
*
* **Who:** Admins only.
*/
post: operations["postSettingsSign-inCheck"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/settings/sign-in/move": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put?: never;
/**
* Move sign-in to Accounts
* @description Copies everyone into the church's Accounts with their passwords and authenticator apps, checks the count, then switches. Nothing switches if anything fails, and it can be run again. Undo for 14 days.
*
* **Who:** Admins only.
*/
post: operations["postSettingsSign-inMove"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/settings/sign-in/undo": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put?: never;
/**
* Undo the move (back to Cross Events' own sign-in)
* @description Within 14 days of the move. People sign in with the password they had at the move; changes made in Accounts since then don't come back here.
*
* **Who:** Admins only.
*/
post: operations["postSettingsSign-inUndo"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/users/{id}/account/reset-two-factor": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put?: never;
/**
* Reset someone's two-step sign-in (in Accounts)
* @description They set it up again at their next sign-in, and are signed out everywhere.
*
* **Who:** Admins only.
*/
post: operations["postUsersIdAccountReset-two-factor"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/users/{id}/account/unlock": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put?: never;
/**
* Unlock someone after too many wrong passwords (in Accounts)
* @description **Who:** Admins only.
*/
post: operations["postUsersIdAccountUnlock"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/users/{id}/account/active": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put?: never;
/**
* Turn someone's church account off or on everywhere (in Accounts)
* @description Off signs them out of every product of the church. To only stop them using Cross Events, deactivate them here instead.
*
* **Who:** Admins only.
*/
post: operations["postUsersIdAccountActive"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
}
export type webhooks = Record<string, never>;
export interface components {
@@ -39597,4 +39769,477 @@ export interface operations {
};
};
};
getAuthMode: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data: {
/** @enum {string} */
mode: "local" | "accounts";
signInUrl: string;
/** @description With `accounts`: the church account page (profile, password, two-step sign-in, privacy) */
accountUrl: string | null;
};
};
};
};
};
};
"getSettingsSign-in": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data: {
/**
* @description local: Cross Events' own sign-in; accounts: through the church's Accounts
* @enum {string}
*/
mode: "local" | "accounts";
accountsConnected: boolean;
accountsUrl: string | null;
movedAt: string | null;
/** @description Undo is possible until then (14 days after the move) */
undoUntil: string | null;
/** @description The old passwords have been removed (Undo is no longer possible) */
secretsCleared: boolean;
running: boolean;
report: unknown | null;
};
};
};
};
/** @description Not signed in (UNAUTHENTICATED) */
401: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not allowed for this role (FORBIDDEN) */
403: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
};
};
"postSettingsSign-inCheck": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data: {
accountsVersion: string;
toMove: number;
wouldCreate: number;
wouldLink: {
name: string;
email: string;
}[];
refused: {
name: string;
email: string;
reason: string;
}[];
skipped: number;
admins: {
name: string;
email: string;
id: string;
}[];
noticeConflict: {
accountsVersions: number[];
eventsVersions: number[];
} | null;
withTwoFactor: number;
};
};
};
};
/** @description Not signed in (UNAUTHENTICATED) */
401: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not allowed for this role (FORBIDDEN) */
403: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
};
};
"postSettingsSign-inMove": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody: {
content: {
"application/json": {
/** @description Events admins who also become Accounts admins */
adminIds: string[];
/** @description When Accounts has its own privacy notice: keep it (everyone accepts it at their next sign-in) instead of Events' */
keepAccountsNotices?: boolean;
};
};
};
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data: {
/**
* @description local: Cross Events' own sign-in; accounts: through the church's Accounts
* @enum {string}
*/
mode: "local" | "accounts";
accountsConnected: boolean;
accountsUrl: string | null;
movedAt: string | null;
/** @description Undo is possible until then (14 days after the move) */
undoUntil: string | null;
/** @description The old passwords have been removed (Undo is no longer possible) */
secretsCleared: boolean;
running: boolean;
report: unknown | null;
};
};
};
};
/** @description Validation failed (VALIDATION_FAILED) */
400: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not signed in (UNAUTHENTICATED) */
401: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not allowed for this role (FORBIDDEN) */
403: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
};
};
"postSettingsSign-inUndo": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data: {
/**
* @description local: Cross Events' own sign-in; accounts: through the church's Accounts
* @enum {string}
*/
mode: "local" | "accounts";
accountsConnected: boolean;
accountsUrl: string | null;
movedAt: string | null;
/** @description Undo is possible until then (14 days after the move) */
undoUntil: string | null;
/** @description The old passwords have been removed (Undo is no longer possible) */
secretsCleared: boolean;
running: boolean;
report: unknown | null;
};
};
};
};
/** @description Not signed in (UNAUTHENTICATED) */
401: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not allowed for this role (FORBIDDEN) */
403: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
};
};
"postUsersIdAccountReset-two-factor": {
parameters: {
query?: never;
header?: never;
path: {
/** @description The id */
id: string;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data: {
/** @constant */
ok: true;
};
};
};
};
/** @description Validation failed (VALIDATION_FAILED) */
400: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not signed in (UNAUTHENTICATED) */
401: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not allowed for this role (FORBIDDEN) */
403: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not found (NOT_FOUND) */
404: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
};
};
postUsersIdAccountUnlock: {
parameters: {
query?: never;
header?: never;
path: {
/** @description The id */
id: string;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data: {
/** @constant */
ok: true;
};
};
};
};
/** @description Validation failed (VALIDATION_FAILED) */
400: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not signed in (UNAUTHENTICATED) */
401: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not allowed for this role (FORBIDDEN) */
403: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not found (NOT_FOUND) */
404: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
};
};
postUsersIdAccountActive: {
parameters: {
query?: never;
header?: never;
path: {
/** @description The id */
id: string;
};
cookie?: never;
};
requestBody: {
content: {
"application/json": {
active: boolean;
};
};
};
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data: {
/** @constant */
ok: true;
};
};
};
};
/** @description Validation failed (VALIDATION_FAILED) */
400: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not signed in (UNAUTHENTICATED) */
401: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not allowed for this role (FORBIDDEN) */
403: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not found (NOT_FOUND) */
404: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
};
};
}
+57
View File
@@ -0,0 +1,57 @@
/**
* Signing in through the church's Accounts (3.0.0, docs/EVENTS-3.0-PLAN.md §3). Once an admin has
* moved sign-in (Settings → Sign-in), `/login`, `/register` and `/forgot-password` forward to
* `GET /api/auth/signin?returnTo=…`, which sends the browser to Accounts and back to the same page.
* Every existing `/login?redirect=…` link keeps working that way.
*/
import { API_BASE } from "@/lib/api";
export type AuthMode = "local" | "accounts";
export type AuthInfo = { mode: AuthMode; accountUrl: string | null };
let infoPromise: Promise<AuthInfo> | null = null;
/**
* Where people sign in, and (through Accounts) the church account page, asked once per page load
* (it only changes when an admin moves sign-in).
*/
export function fetchAuthInfo(): Promise<AuthInfo> {
if (!infoPromise) {
infoPromise = fetch(`${API_BASE}/api/v2/auth/mode`, { headers: { Accept: "application/json" } })
.then((r) => (r.ok ? r.json() : null))
.then((j: { data?: { mode?: AuthMode; accountUrl?: string | null } } | null): AuthInfo => ({
mode: j?.data?.mode === "accounts" ? "accounts" : "local",
accountUrl: j?.data?.accountUrl ?? null,
}))
.catch(() => {
infoPromise = null;
return { mode: "local" as const, accountUrl: null };
});
}
return infoPromise;
}
export function fetchAuthMode(): Promise<AuthMode> {
return fetchAuthInfo().then((i) => i.mode);
}
/** A relative path on this site, or the fallback: never another site (the backend checks too). */
export function safePath(raw: string | null | undefined, fallback = "/dashboard"): string {
const s = String(raw ?? "");
return s.startsWith("/") && !s.startsWith("//") && !s.startsWith("/\\") ? s : fallback;
}
/** The address that signs someone in through Accounts and brings them back to `returnTo`. */
export function signInHref(returnTo: string, opts: { signUp?: boolean; email?: string } = {}): string {
const q = new URLSearchParams({ returnTo: safePath(returnTo) });
if (opts.signUp) q.set("signup", "1");
if (opts.email) q.set("email", opts.email);
return `${API_BASE}/api/auth/signin?${q.toString()}`;
}
/** The page someone is on now (path and query), to come back to after signing in. */
export function currentPage(): string {
if (typeof window === "undefined") return "/";
return `${window.location.pathname}${window.location.search}`;
}