@extantape/payload-plugin-hats 0.0.0-stage → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +74 -2
- package/dist/access.d.ts +13 -0
- package/dist/access.js +30 -0
- package/dist/client/HatSwitcher.d.ts +10 -0
- package/dist/client/HatSwitcher.js +101 -0
- package/dist/client/LinkedAccounts.d.ts +10 -0
- package/dist/client/LinkedAccounts.js +59 -0
- package/dist/client/api.d.ts +95 -0
- package/dist/client/api.js +62 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +4 -0
- package/dist/collections.d.ts +3 -0
- package/dist/collections.js +131 -0
- package/dist/endpoints.d.ts +4 -0
- package/dist/endpoints.js +342 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +81 -0
- package/dist/sessions.d.ts +44 -0
- package/dist/sessions.js +162 -0
- package/dist/state.d.ts +13 -0
- package/dist/state.js +29 -0
- package/dist/types.d.ts +146 -0
- package/dist/types.js +3 -0
- package/package.json +72 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 EXTANT APE
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,75 @@
|
|
|
1
|
-
#
|
|
1
|
+
# payload-plugin-hats
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Linked accounts and role hats for Payload. One person links their accounts and switches between them, and an account with several roles acts in one at a time. Switching up into a sensitive role asks for a second factor.
|
|
4
|
+
|
|
5
|
+
**Status:** early, 0.x. The server side passes 22 tests against a real Payload 3.92 and MongoDB, with made-up roles and a fake second factor. The two React components were tried in a browser on a local copy of a real site (2026-11-09) with made-up accounts: keyboard, a real authenticator code, the approval form, and axe with 0 findings on the switch, the code prompt and the linking section in light and dark. It isn't in use on any site yet.
|
|
6
|
+
|
|
7
|
+
## What it does
|
|
8
|
+
|
|
9
|
+
- **Linked accounts.** Up to 4 accounts per person. Linking needs both emails confirmed and an approver who isn't in the set. Unlinking is self-serve and immediate.
|
|
10
|
+
- **Hats.** Wearing a hat narrows the user before `req.user` exists, so every access rule follows it: admin, REST, GraphQL and the Local API with `req`. If narrowing fails, the request is signed out, never given full roles.
|
|
11
|
+
- **Step-up.** Switching into a sensitive hat asks for that account's second factor, remembered for 3 hours per account.
|
|
12
|
+
- **Revocation.** Unlinking, deleting a row, losing a role or deleting an account ends every session switched into or through it. Switched sessions also re-check their set on every request. An ended session's record is kept, marked revoked, so a session that Payload writes back by accident (two writes to an account's sessions at once) stays signed out. Old records are deleted once their Payload session is gone, at most 50 per switch.
|
|
13
|
+
- **Link limits.** Pass `limit` to rate-limit link requests, per person and per email address. It must answer exactly `true` to allow one. Any other answer, or a throw, refuses the request with `tooMany` (429) and nothing is sent.
|
|
14
|
+
|
|
15
|
+
Needs Payload sessions (`auth.useSessions`, on by default).
|
|
16
|
+
|
|
17
|
+
## On its own, and with others
|
|
18
|
+
|
|
19
|
+
**On its own:** it needs a users auth collection with Payload sessions, plus your `hatsOf` and `wear`, built from the roles you already have. Linking stays off until you set `canApproveLinks`, and switching into a sensitive hat is refused until you give it a `stepUp`.
|
|
20
|
+
|
|
21
|
+
**Only `true` counts.** `canApproveLinks`, `stepUp.available`, `stepUp.verify` and `limit` must answer exactly `true` (or a promise of it). Anything else is a no: `false`, `1`, `'yes'`, an object such as `{ valid: false }`, or an error thrown or rejected. A refused step-up answers 403 (`setUpTwoStep` or `wrongCode`), a refused approval 403 and a refused link request 429 (`tooMany`), never a 500. If your verifier returns a result object, pass its flag: `verify: async (a) => (await check(a)).valid === true`.
|
|
22
|
+
|
|
23
|
+
**Only `null` goes ahead.** `blocked(req)` answers a reason or `null`. A non-empty string refuses switching, linking and unlinking with 409 (`blocked`) and your reason. `null` or `undefined` goes ahead. Anything else, such as `''`, `false` or an object, and an error thrown or rejected, also refuses with 409 `blocked` and a general reason, never a 500.
|
|
24
|
+
|
|
25
|
+
**Works with:**
|
|
26
|
+
- **MFA:** MFA's `isOnFor` and `verify` make the `stepUp`. MFA's README has the two lines.
|
|
27
|
+
- **Masq:** your `blocked(req)` can refuse switching while masquerading, using Masq's `masqStateOf`. Masq's `canMasquerade` should refuse a switched session, using `hatsStateOf(user).via`.
|
|
28
|
+
- **Guardians:** Hats can be the switcher behind Guardians' required `actingFor`, so a guardian who switched into a kid's account is still seen as the guardian.
|
|
29
|
+
- **Audit Trail:** pass `onEvent` through Audit Trail's `fromPluginEvent`, and use `hatsStateOf(req)` in its `via`, so an entry says which account signed in and which hat was worn.
|
|
30
|
+
|
|
31
|
+
None of these are imported. The site connects them in its own config.
|
|
32
|
+
|
|
33
|
+
**Family:** It's part of the **Identity** family (a working draft): plugins designed to sit together for accounts and access.
|
|
34
|
+
|
|
35
|
+
## Use
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { hats } from '@extantape/payload-plugin-hats'
|
|
39
|
+
|
|
40
|
+
hats({
|
|
41
|
+
hatsOf: (user) => [{ id: 'member', label: 'Member' }, { id: 'admin', label: 'Administrator', sensitive: true }],
|
|
42
|
+
wear: (user, hat) => ({ ...user, roles: hat === 'admin' ? user.roles : ['member'] }),
|
|
43
|
+
canApproveLinks: ({ user }) => user.roles.includes('admin'),
|
|
44
|
+
stepUp: { available: (user) => hasAuthenticator(user), verify: ({ user, code }) => checkCode(user, code) },
|
|
45
|
+
limit: ({ user, email }) => allowAttempt('hatsLink', `${user.id}:${email}`), // optional
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`wear` must return a narrowed copy of the user, never the user itself: Hats refuses the request if it gets the same object back, if a hat adds one the account doesn't hold, or if an ordinary hat keeps a sensitive one.
|
|
50
|
+
|
|
51
|
+
Endpoints, under the API route:
|
|
52
|
+
|
|
53
|
+
- `GET /hats` lists the acting account, its hats and its linked accounts.
|
|
54
|
+
- `POST /hats/switch { account?, hat, code? }` switches hat or account.
|
|
55
|
+
- `POST /hats/link { email }` asks to link another account.
|
|
56
|
+
- `GET` and `POST /hats/confirm` handle the email confirmation.
|
|
57
|
+
- `POST /hats/unlink { account? }` takes an account out of the set.
|
|
58
|
+
|
|
59
|
+
Approvers approve in the admin, under Accounts → Linked accounts.
|
|
60
|
+
|
|
61
|
+
The switch goes in the admin header (turn it off with `adminSwitch: false`). For a site's own pages, `@extantape/payload-plugin-hats/client` has `HatSwitcher` for the header and `LinkedAccounts` for the account page. They need no Payload UI package. By default they take the surrounding text color, and they follow `--hats-ink`, `--hats-paper`, `--hats-line`, `--hats-muted` and `--hats-focus` if you set them.
|
|
62
|
+
|
|
63
|
+
Every word is replaceable for translation: pass `text` (see `defaultText`). Server answers carry a stable `reason` (for example `wrongCode`), and `text.reasons` gives your words for each; anything you leave out shows the English.
|
|
64
|
+
|
|
65
|
+
## Commands
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npm test # Vitest, in-memory MongoDB
|
|
69
|
+
npm run typecheck
|
|
70
|
+
npm run build
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT. See `LICENSE`.
|
package/dist/access.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Only an answer of exactly `true` passes. Anything else is a no: `false`, a truthy value such as `1`, `'yes'` or
|
|
3
|
+
* `{ valid: false }`, and an error thrown or rejected (so a broken check refuses with a 401 or 403, never a 500).
|
|
4
|
+
*/
|
|
5
|
+
export declare function exactlyTrue(check: () => unknown): Promise<boolean>;
|
|
6
|
+
/** Said when the site's `blocked` check fails or answers something other than a reason or null. */
|
|
7
|
+
export declare const CANT_CHECK = "Switching isn\u2019t available right now. Try again later.";
|
|
8
|
+
/**
|
|
9
|
+
* The site's `blocked` answer as a refusal reason, or null to go ahead. Only `null` (or no answer, `undefined`) goes
|
|
10
|
+
* ahead. A non-empty string is the site's own reason. Anything else, `''`, `false`, `1` or an object included, and an
|
|
11
|
+
* error thrown or rejected, is still a refusal, with a general reason (so a broken check refuses with a 409, never a 500).
|
|
12
|
+
*/
|
|
13
|
+
export declare function blockedBy(check: () => unknown): Promise<string | null>;
|
package/dist/access.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Only an answer of exactly `true` passes. Anything else is a no: `false`, a truthy value such as `1`, `'yes'` or
|
|
3
|
+
* `{ valid: false }`, and an error thrown or rejected (so a broken check refuses with a 401 or 403, never a 500).
|
|
4
|
+
*/
|
|
5
|
+
export async function exactlyTrue(check) {
|
|
6
|
+
try {
|
|
7
|
+
return (await check()) === true;
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** Said when the site's `blocked` check fails or answers something other than a reason or null. */
|
|
14
|
+
export const CANT_CHECK = 'Switching isn’t available right now. Try again later.';
|
|
15
|
+
/**
|
|
16
|
+
* The site's `blocked` answer as a refusal reason, or null to go ahead. Only `null` (or no answer, `undefined`) goes
|
|
17
|
+
* ahead. A non-empty string is the site's own reason. Anything else, `''`, `false`, `1` or an object included, and an
|
|
18
|
+
* error thrown or rejected, is still a refusal, with a general reason (so a broken check refuses with a 409, never a 500).
|
|
19
|
+
*/
|
|
20
|
+
export async function blockedBy(check) {
|
|
21
|
+
try {
|
|
22
|
+
const why = await check();
|
|
23
|
+
if (why === null || why === undefined)
|
|
24
|
+
return null;
|
|
25
|
+
return typeof why === 'string' && why.trim() ? why : CANT_CHECK;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return CANT_CHECK;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type HatsText } from './api.js';
|
|
2
|
+
/**
|
|
3
|
+
* The switch: which account and hat you're acting as, and the others you can switch to. Renders nothing for an
|
|
4
|
+
* account with nothing to switch to. A sensitive choice asks for that account's code inline. Reloads after a switch.
|
|
5
|
+
*/
|
|
6
|
+
export declare function HatSwitcher({ apiRoute, onSwitched, text }: {
|
|
7
|
+
apiRoute?: string;
|
|
8
|
+
onSwitched?: () => void;
|
|
9
|
+
text?: Partial<HatsText>;
|
|
10
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useEffect, useId, useRef, useState } from 'react';
|
|
4
|
+
import { defaultText, hatsApi } from './api.js';
|
|
5
|
+
const v = (name, fallback) => `var(--hats-${name}, ${fallback})`;
|
|
6
|
+
const ink = v('ink', 'currentColor');
|
|
7
|
+
const paper = v('paper', 'var(--theme-elevation-0, Canvas)');
|
|
8
|
+
const line = v('line', 'color-mix(in srgb, currentColor 45%, transparent)');
|
|
9
|
+
// Muted text is the surrounding text color, slightly faded, so it keeps its contrast on light and dark pages.
|
|
10
|
+
const muted = v('muted', 'color-mix(in srgb, currentColor 78%, transparent)');
|
|
11
|
+
const focus = v('focus', '#b85c00');
|
|
12
|
+
const s = {
|
|
13
|
+
wrap: { position: 'relative', display: 'inline-block', font: 'inherit', color: ink },
|
|
14
|
+
button: { font: 'inherit', color: ink, background: paper, border: `1px solid ${line}`, borderRadius: 6, minHeight: 32, padding: '4px 10px', cursor: 'pointer' },
|
|
15
|
+
panel: { position: 'absolute', insetInlineEnd: 0, top: 'calc(100% + 6px)', zIndex: 50, minWidth: 'min(90vw, 320px)', maxWidth: 'min(90vw, 380px)', background: paper, color: ink, border: `1px solid ${line}`, borderRadius: 8, padding: 12, boxShadow: '0 6px 24px rgb(0 0 0 / 0.18)', whiteSpace: 'normal', overflowWrap: 'anywhere', textAlign: 'start' },
|
|
16
|
+
heading: { fontSize: '0.85em', fontWeight: 600, margin: '8px 0 4px', color: muted },
|
|
17
|
+
list: { listStyle: 'none', margin: 0, padding: 0 },
|
|
18
|
+
item: { font: 'inherit', whiteSpace: 'normal', overflowWrap: 'anywhere', color: ink, background: 'transparent', border: 0, borderRadius: 4, width: '100%', textAlign: 'start', padding: '6px 8px', minHeight: 32, cursor: 'pointer' },
|
|
19
|
+
note: { fontSize: '0.85em', color: muted },
|
|
20
|
+
input: { font: 'inherit', color: ink, background: paper, border: `1px solid ${line}`, borderRadius: 4, padding: '4px 8px', minHeight: 32, width: '9em', letterSpacing: '0.1em' },
|
|
21
|
+
error: { color: v('error', '#b00020'), fontSize: '0.9em', margin: '6px 0 0' },
|
|
22
|
+
};
|
|
23
|
+
const focusRing = `.hats-switcher :focus-visible{outline:3px solid ${focus};outline-offset:2px}.hats-switcher [aria-current="true"]{font-weight:600}`;
|
|
24
|
+
/**
|
|
25
|
+
* The switch: which account and hat you're acting as, and the others you can switch to. Renders nothing for an
|
|
26
|
+
* account with nothing to switch to. A sensitive choice asks for that account's code inline. Reloads after a switch.
|
|
27
|
+
*/
|
|
28
|
+
export function HatSwitcher({ apiRoute = '/api', onSwitched, text }) {
|
|
29
|
+
const t = { ...defaultText, ...text };
|
|
30
|
+
const api = hatsApi(apiRoute, t);
|
|
31
|
+
const [menu, setMenu] = useState(null);
|
|
32
|
+
const [open, setOpen] = useState(false);
|
|
33
|
+
const [asking, setAsking] = useState(null);
|
|
34
|
+
const [code, setCode] = useState('');
|
|
35
|
+
const [error, setError] = useState('');
|
|
36
|
+
const [busy, setBusy] = useState(false);
|
|
37
|
+
const button = useRef(null);
|
|
38
|
+
const wrap = useRef(null);
|
|
39
|
+
const codeBox = useRef(null);
|
|
40
|
+
const panelId = useId();
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
void api.menu().then(setMenu);
|
|
43
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
44
|
+
}, [apiRoute]);
|
|
45
|
+
const close = useCallback(() => {
|
|
46
|
+
setOpen(false);
|
|
47
|
+
setAsking(null);
|
|
48
|
+
setError('');
|
|
49
|
+
setCode('');
|
|
50
|
+
button.current?.focus();
|
|
51
|
+
}, []);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (!open)
|
|
54
|
+
return;
|
|
55
|
+
const onKey = (e) => e.key === 'Escape' && close();
|
|
56
|
+
const onClick = (e) => !wrap.current?.contains(e.target) && close();
|
|
57
|
+
document.addEventListener('keydown', onKey);
|
|
58
|
+
document.addEventListener('mousedown', onClick);
|
|
59
|
+
return () => {
|
|
60
|
+
document.removeEventListener('keydown', onKey);
|
|
61
|
+
document.removeEventListener('mousedown', onClick);
|
|
62
|
+
};
|
|
63
|
+
}, [open, close]);
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (asking)
|
|
66
|
+
codeBox.current?.focus();
|
|
67
|
+
}, [asking]);
|
|
68
|
+
if (!menu?.signedIn || !menu.showSwitch)
|
|
69
|
+
return null;
|
|
70
|
+
const current = menu.hats.find((h) => h.id === menu.hat) ?? menu.hats.at(-1);
|
|
71
|
+
const signedInAs = String(menu.signedInAs) === String(menu.account.id) ? null : menu.linked.find((l) => String(l.id) === String(menu.signedInAs));
|
|
72
|
+
async function go(choice, withCode) {
|
|
73
|
+
setBusy(true);
|
|
74
|
+
setError('');
|
|
75
|
+
const res = await api.switchTo({ account: choice.account, hat: choice.hat.id, code: withCode });
|
|
76
|
+
setBusy(false);
|
|
77
|
+
if (res.ok) {
|
|
78
|
+
if (onSwitched)
|
|
79
|
+
onSwitched();
|
|
80
|
+
else
|
|
81
|
+
window.location.reload();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (res.needsCode) {
|
|
85
|
+
setAsking(choice);
|
|
86
|
+
if (withCode)
|
|
87
|
+
setError(t.enterCode);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
setError(res.message);
|
|
91
|
+
}
|
|
92
|
+
const choose = (choice) => (choice.hat.needsCode ? (setAsking(choice), setError('')) : void go(choice));
|
|
93
|
+
const hatList = (account, accountLabel, hats, isCurrent) => (_jsx("ul", { style: s.list, children: hats.map((h) => {
|
|
94
|
+
const on = isCurrent && h.id === current?.id;
|
|
95
|
+
return (_jsx("li", { children: _jsxs("button", { type: "button", style: s.item, "aria-current": on ? 'true' : undefined, disabled: busy || on, onClick: () => choose({ account, accountLabel, hat: h }), children: [on ? '✓ ' : '', h.label, h.needsCode && !on ? _jsxs("span", { style: s.note, children: [" \u00B7 ", t.asksForCode] }) : null] }) }, h.id));
|
|
96
|
+
}) }));
|
|
97
|
+
return (_jsxs("div", { className: "hats-switcher", style: s.wrap, ref: wrap, children: [_jsx("style", { children: focusRing }), _jsxs("button", { ref: button, type: "button", style: s.button, "aria-expanded": open, "aria-controls": panelId, onClick: () => (open ? close() : setOpen(true)), children: [menu.linked.length ? `${menu.account.label} · ` : '', current?.label ?? t.switchFallback, _jsx("span", { "aria-hidden": "true", children: " \u25BE" }), _jsxs("span", { style: { position: 'absolute', width: 1, height: 1, overflow: 'hidden', clip: 'rect(0 0 0 0)' }, children: [": ", t.switchHint] })] }), open ? (_jsxs("div", { id: panelId, style: s.panel, role: "group", "aria-label": t.switchGroup, children: [signedInAs ? (_jsx("p", { style: s.note, children: t.signedInAs(signedInAs.label, menu.account.label) })) : null, asking ? (_jsxs("form", { onSubmit: (e) => {
|
|
98
|
+
e.preventDefault();
|
|
99
|
+
void go(asking, code.trim());
|
|
100
|
+
}, children: [_jsx("label", { htmlFor: `${panelId}-code`, style: { display: 'block', marginBottom: 6 }, children: t.codeLabel(asking.hat.label, asking.account !== undefined || signedInAs ? asking.accountLabel : null) }), _jsx("input", { ref: codeBox, id: `${panelId}-code`, style: s.input, value: code, onChange: (e) => setCode(e.target.value), autoComplete: "one-time-code", inputMode: "numeric", required: true }), ' ', _jsx("button", { type: "submit", style: s.button, disabled: busy, children: t.switchButton }), ' ', _jsx("button", { type: "button", style: s.button, onClick: () => (setAsking(null), setError('')), children: t.back })] })) : (_jsxs(_Fragment, { children: [_jsx("p", { style: s.heading, children: menu.linked.length ? menu.account.label : t.actAs }), hatList(undefined, menu.account.label, menu.hats, true), menu.linked.map((l) => (_jsxs("div", { children: [_jsx("p", { style: s.heading, children: l.label }), hatList(l.id, l.label, l.hats, false)] }, String(l.id))))] })), _jsx("p", { role: "alert", style: s.error, children: error })] })) : null] }));
|
|
101
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type HatsText } from './api.js';
|
|
2
|
+
/**
|
|
3
|
+
* The account-page section for linking: the accounts in your set and where each stands, a form to ask for another,
|
|
4
|
+
* and unlinking (it ends any session switched through that account straight away).
|
|
5
|
+
*/
|
|
6
|
+
export declare function LinkedAccounts({ apiRoute, text, headingClassName }: {
|
|
7
|
+
apiRoute?: string;
|
|
8
|
+
text?: Partial<HatsText>;
|
|
9
|
+
headingClassName?: string;
|
|
10
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useState } from 'react';
|
|
4
|
+
import { defaultText, hatsApi } from './api.js';
|
|
5
|
+
const v = (name, fallback) => `var(--hats-${name}, ${fallback})`;
|
|
6
|
+
const ink = v('ink', 'currentColor');
|
|
7
|
+
const line = v('line', 'color-mix(in srgb, currentColor 45%, transparent)');
|
|
8
|
+
// Muted text is the surrounding text color, slightly faded, so it keeps its contrast on light and dark pages.
|
|
9
|
+
const muted = v('muted', 'color-mix(in srgb, currentColor 78%, transparent)');
|
|
10
|
+
const s = {
|
|
11
|
+
list: { listStyle: 'none', margin: '0 0 16px', padding: 0 },
|
|
12
|
+
row: { display: 'flex', flexWrap: 'wrap', gap: 8, alignItems: 'center', justifyContent: 'space-between', padding: '8px 0', borderBottom: `1px solid ${line}` },
|
|
13
|
+
note: { color: muted, fontSize: '0.9em', margin: '2px 0 0' },
|
|
14
|
+
button: { font: 'inherit', color: ink, background: 'transparent', border: `1px solid ${line}`, borderRadius: 6, minHeight: 32, padding: '4px 12px', cursor: 'pointer' },
|
|
15
|
+
input: { font: 'inherit', color: ink, background: 'transparent', border: `1px solid ${line}`, borderRadius: 4, padding: '4px 8px', minHeight: 32, minWidth: '16em' },
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The account-page section for linking: the accounts in your set and where each stands, a form to ask for another,
|
|
19
|
+
* and unlinking (it ends any session switched through that account straight away).
|
|
20
|
+
*/
|
|
21
|
+
export function LinkedAccounts({ apiRoute = '/api', text, headingClassName }) {
|
|
22
|
+
const t = { ...defaultText, ...text };
|
|
23
|
+
const api = hatsApi(apiRoute, t);
|
|
24
|
+
const [menu, setMenu] = useState(null);
|
|
25
|
+
const [email, setEmail] = useState('');
|
|
26
|
+
const [said, setSaid] = useState('');
|
|
27
|
+
const [busy, setBusy] = useState(false);
|
|
28
|
+
const [unlinking, setUnlinking] = useState(null);
|
|
29
|
+
const id = useId();
|
|
30
|
+
const reload = () => api.menu().then(setMenu);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
void reload();
|
|
33
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
34
|
+
}, [apiRoute]);
|
|
35
|
+
if (!menu?.signedIn || !menu.canLink)
|
|
36
|
+
return null;
|
|
37
|
+
const full = menu.set.length >= menu.maxLinked;
|
|
38
|
+
async function request(e) {
|
|
39
|
+
e.preventDefault();
|
|
40
|
+
setBusy(true);
|
|
41
|
+
const res = await api.link(email.trim());
|
|
42
|
+
setBusy(false);
|
|
43
|
+
setSaid(res.message);
|
|
44
|
+
if (res.ok)
|
|
45
|
+
setEmail('');
|
|
46
|
+
await reload();
|
|
47
|
+
}
|
|
48
|
+
async function unlink(account, you) {
|
|
49
|
+
setBusy(true);
|
|
50
|
+
const res = await api.unlink(account);
|
|
51
|
+
setBusy(false);
|
|
52
|
+
setUnlinking(null);
|
|
53
|
+
if (res.ok && res.body.signedOut)
|
|
54
|
+
return window.location.reload();
|
|
55
|
+
setSaid(res.ok ? (you ? t.youUnlinked : t.unlinked) : res.message);
|
|
56
|
+
await reload();
|
|
57
|
+
}
|
|
58
|
+
return (_jsxs("section", { "aria-labelledby": `${id}-h`, children: [_jsx("h2", { id: `${id}-h`, className: headingClassName, children: t.linkedHeading }), _jsx("p", { style: s.note, children: t.linkedIntro(menu.maxLinked) }), menu.set.length ? (_jsx("ul", { style: s.list, children: menu.set.map((m) => (_jsxs("li", { style: s.row, children: [_jsxs("div", { children: [_jsx("strong", { children: m.label }), m.you ? ` ${t.thisAccount}` : '', _jsx("p", { style: s.note, children: t.status(m.status, m.you) })] }), unlinking === m.id ? (_jsxs("div", { role: "group", "aria-label": t.unlinkAsk(m.label), children: [_jsxs("span", { children: [t.unlinkAsk(m.you ? null : m.label), " "] }), _jsx("button", { type: "button", style: s.button, disabled: busy, onClick: () => void unlink(m.id, m.you), children: t.unlink }), ' ', _jsx("button", { type: "button", style: s.button, onClick: () => setUnlinking(null), children: t.keep })] })) : (_jsx("button", { type: "button", style: s.button, disabled: busy, onClick: () => setUnlinking(m.id), "aria-label": t.unlinkNamed(m.label), children: t.unlink }))] }, String(m.id)))) })) : null, full ? (_jsx("p", { style: s.note, children: t.setFull })) : (_jsxs("form", { onSubmit: (e) => void request(e), children: [_jsx("label", { htmlFor: `${id}-email`, style: { display: 'block', marginBottom: 6 }, children: t.emailLabel }), _jsx("input", { id: `${id}-email`, type: "email", autoComplete: "off", required: true, style: s.input, value: email, onChange: (e) => setEmail(e.target.value) }), ' ', _jsx("button", { type: "submit", style: s.button, disabled: busy || !email.trim(), children: t.send })] })), _jsx("p", { role: "status", style: s.note, children: said })] }));
|
|
59
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/** What `GET /api/hats` answers, and the calls the components make. No Payload UI dependency, so a site can use them too. */
|
|
2
|
+
export type MenuHat = {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
sensitive?: boolean;
|
|
6
|
+
needsCode: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type HatsMenu = {
|
|
9
|
+
signedIn: false;
|
|
10
|
+
} | {
|
|
11
|
+
signedIn: true;
|
|
12
|
+
account: {
|
|
13
|
+
id: string | number;
|
|
14
|
+
label: string;
|
|
15
|
+
};
|
|
16
|
+
signedInAs: string;
|
|
17
|
+
hat: string | null;
|
|
18
|
+
hats: MenuHat[];
|
|
19
|
+
linked: {
|
|
20
|
+
id: string | number;
|
|
21
|
+
label: string;
|
|
22
|
+
hats: MenuHat[];
|
|
23
|
+
}[];
|
|
24
|
+
link: string | null;
|
|
25
|
+
set: {
|
|
26
|
+
id: string | number;
|
|
27
|
+
label: string;
|
|
28
|
+
status: 'requested' | 'confirmed' | 'approved';
|
|
29
|
+
you: boolean;
|
|
30
|
+
}[];
|
|
31
|
+
canLink: boolean;
|
|
32
|
+
showSwitch: boolean;
|
|
33
|
+
maxLinked: number;
|
|
34
|
+
};
|
|
35
|
+
export type Answer = {
|
|
36
|
+
ok: boolean;
|
|
37
|
+
status: number;
|
|
38
|
+
message: string;
|
|
39
|
+
reason?: string;
|
|
40
|
+
needsCode?: boolean;
|
|
41
|
+
body: Record<string, unknown>;
|
|
42
|
+
};
|
|
43
|
+
type Words = {
|
|
44
|
+
offline: string;
|
|
45
|
+
failed: string;
|
|
46
|
+
reasons?: Partial<Record<string, string>>;
|
|
47
|
+
};
|
|
48
|
+
export declare const hatsApi: (apiRoute?: string, words?: Words) => {
|
|
49
|
+
menu: () => Promise<HatsMenu>;
|
|
50
|
+
switchTo: (to: {
|
|
51
|
+
account?: string | number;
|
|
52
|
+
hat: string;
|
|
53
|
+
code?: string;
|
|
54
|
+
}) => Promise<Answer>;
|
|
55
|
+
link: (email: string) => Promise<Answer>;
|
|
56
|
+
unlink: (account: string | number) => Promise<Answer>;
|
|
57
|
+
};
|
|
58
|
+
/** Plain words for a member's status, for the account page. */
|
|
59
|
+
export declare const statusText: (status: string, you: boolean) => "Linked" | "Confirmed. Waiting for an administrator to approve it." | "Waiting for you to confirm from this account’s email." | "Waiting for its email to be confirmed.";
|
|
60
|
+
/** Every word the components show, so a site can pass its own translations. English by default. */
|
|
61
|
+
export declare const defaultText: {
|
|
62
|
+
switchHint: string;
|
|
63
|
+
switchGroup: string;
|
|
64
|
+
switchFallback: string;
|
|
65
|
+
actAs: string;
|
|
66
|
+
asksForCode: string;
|
|
67
|
+
signedInAs: (signedIn: string, acting: string) => string;
|
|
68
|
+
codeLabel: (hat: string, account: string | null) => string;
|
|
69
|
+
enterCode: string;
|
|
70
|
+
switchButton: string;
|
|
71
|
+
back: string;
|
|
72
|
+
offline: string;
|
|
73
|
+
failed: string;
|
|
74
|
+
linkedHeading: string;
|
|
75
|
+
linkedIntro: (max: number) => string;
|
|
76
|
+
thisAccount: string;
|
|
77
|
+
status: (status: string, you: boolean) => "Linked" | "Confirmed. Waiting for an administrator to approve it." | "Waiting for you to confirm from this account’s email." | "Waiting for its email to be confirmed.";
|
|
78
|
+
unlinkAsk: (label: string | null) => string;
|
|
79
|
+
unlink: string;
|
|
80
|
+
unlinkNamed: (label: string) => string;
|
|
81
|
+
keep: string;
|
|
82
|
+
setFull: string;
|
|
83
|
+
emailLabel: string;
|
|
84
|
+
send: string;
|
|
85
|
+
youUnlinked: string;
|
|
86
|
+
unlinked: string;
|
|
87
|
+
/**
|
|
88
|
+
* Your words for the server's answers, by reason: signIn, blocked, notLinked, notAvailable, chooseHat,
|
|
89
|
+
* noSecondFactor, setUpTwoStep, needsCode, wrongCode, linkingOff, enterEmail, setFull, linkSent, notInSet.
|
|
90
|
+
* A reason left out shows the server's English.
|
|
91
|
+
*/
|
|
92
|
+
reasons: Partial<Record<string, string>>;
|
|
93
|
+
};
|
|
94
|
+
export type HatsText = typeof defaultText;
|
|
95
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
async function send(url, init, words = { offline: 'Couldn’t reach the site. Check your connection and try again.', failed: 'Something went wrong. Try again.' }) {
|
|
2
|
+
try {
|
|
3
|
+
const res = await fetch(url, { credentials: 'include', ...init, headers: { 'Content-Type': 'application/json', ...init?.headers } });
|
|
4
|
+
const body = (await res.json().catch(() => ({})));
|
|
5
|
+
const errors = body.errors;
|
|
6
|
+
const reason = (errors?.[0]?.data?.reason ?? body.reason);
|
|
7
|
+
// The site's own words for this reason, when it gave some; otherwise the server's English.
|
|
8
|
+
const message = String((reason && words.reasons?.[reason]) ?? errors?.[0]?.message ?? body.message ?? (res.ok ? '' : words.failed));
|
|
9
|
+
return { ok: res.ok, status: res.status, message, reason, needsCode: body.needsCode === true, body };
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return { ok: false, status: 0, message: words.offline, body: {} };
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export const hatsApi = (apiRoute = '/api', words) => ({
|
|
16
|
+
menu: async () => (await send(`${apiRoute}/hats`, { cache: 'no-store' }, words)).body,
|
|
17
|
+
switchTo: (to) => send(`${apiRoute}/hats/switch`, { method: 'POST', body: JSON.stringify(to) }, words),
|
|
18
|
+
link: (email) => send(`${apiRoute}/hats/link`, { method: 'POST', body: JSON.stringify({ email }) }, words),
|
|
19
|
+
unlink: (account) => send(`${apiRoute}/hats/unlink`, { method: 'POST', body: JSON.stringify({ account }) }, words),
|
|
20
|
+
});
|
|
21
|
+
/** Plain words for a member's status, for the account page. */
|
|
22
|
+
export const statusText = (status, you) => status === 'approved'
|
|
23
|
+
? 'Linked'
|
|
24
|
+
: status === 'confirmed'
|
|
25
|
+
? 'Confirmed. Waiting for an administrator to approve it.'
|
|
26
|
+
: you
|
|
27
|
+
? 'Waiting for you to confirm from this account’s email.'
|
|
28
|
+
: 'Waiting for its email to be confirmed.';
|
|
29
|
+
/** Every word the components show, so a site can pass its own translations. English by default. */
|
|
30
|
+
export const defaultText = {
|
|
31
|
+
switchHint: 'switch account or role',
|
|
32
|
+
switchGroup: 'Switch account or role',
|
|
33
|
+
switchFallback: 'Switch',
|
|
34
|
+
actAs: 'Act as',
|
|
35
|
+
asksForCode: 'asks for a code',
|
|
36
|
+
signedInAs: (signedIn, acting) => `Signed in as ${signedIn}, acting as ${acting}.`,
|
|
37
|
+
codeLabel: (hat, account) => account ? `To act as ${hat} on ${account}, enter a code from that account’s authenticator app.` : `To act as ${hat}, enter a code from your authenticator app.`,
|
|
38
|
+
enterCode: 'Enter the code.',
|
|
39
|
+
switchButton: 'Switch',
|
|
40
|
+
back: 'Back',
|
|
41
|
+
offline: 'Couldn’t reach the site. Check your connection and try again.',
|
|
42
|
+
failed: 'Something went wrong. Try again.',
|
|
43
|
+
linkedHeading: 'Linked accounts',
|
|
44
|
+
linkedIntro: (max) => `Link up to ${max} of your own accounts to switch between them without signing in again. Each keeps its own email and roles. Both emails confirm the link, then an administrator approves it.`,
|
|
45
|
+
thisAccount: '(this account)',
|
|
46
|
+
status: statusText,
|
|
47
|
+
unlinkAsk: (label) => `Unlink ${label ?? 'this account'}?`,
|
|
48
|
+
unlink: 'Unlink',
|
|
49
|
+
unlinkNamed: (label) => `Unlink ${label}`,
|
|
50
|
+
keep: 'Keep',
|
|
51
|
+
setFull: 'This set has the most accounts it can hold.',
|
|
52
|
+
emailLabel: 'Email of another account of yours',
|
|
53
|
+
send: 'Send confirmation emails',
|
|
54
|
+
youUnlinked: 'This account is no longer linked.',
|
|
55
|
+
unlinked: 'Unlinked.',
|
|
56
|
+
/**
|
|
57
|
+
* Your words for the server's answers, by reason: signIn, blocked, notLinked, notAvailable, chooseHat,
|
|
58
|
+
* noSecondFactor, setUpTwoStep, needsCode, wrongCode, linkingOff, enterEmail, setFull, linkSent, notInSet.
|
|
59
|
+
* A reason left out shows the server's English.
|
|
60
|
+
*/
|
|
61
|
+
reasons: {},
|
|
62
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { APIError } from 'payload';
|
|
2
|
+
import { exactlyTrue } from './access.js';
|
|
3
|
+
import { dissolveIfAlone, revokeSessions } from './sessions.js';
|
|
4
|
+
import { hatsStateOf, idOf } from './state.js';
|
|
5
|
+
import { LINKS, MEMBERS, SESSIONS } from './types.js';
|
|
6
|
+
const internal = (req) => req.context?.hatsInternal === true;
|
|
7
|
+
/**
|
|
8
|
+
* Whether the request's user may approve links. A person never approves their own link: an approver who is (or
|
|
9
|
+
* who signed in as) a member of the set is refused, so the owner's own links need another approver. Only an exact
|
|
10
|
+
* `true` from `canApproveLinks` counts: a truthy value or a thrown error is a no.
|
|
11
|
+
*/
|
|
12
|
+
async function approver(opts, req) {
|
|
13
|
+
const user = req.user;
|
|
14
|
+
if (!user || user.collection !== opts.users || !opts.canApproveLinks)
|
|
15
|
+
return false;
|
|
16
|
+
const ask = opts.canApproveLinks;
|
|
17
|
+
return exactlyTrue(() => ask({ req, user }));
|
|
18
|
+
}
|
|
19
|
+
export function hatCollections(opts) {
|
|
20
|
+
const canApprove = ({ req }) => approver(opts, req);
|
|
21
|
+
const never = () => false;
|
|
22
|
+
const links = {
|
|
23
|
+
slug: LINKS,
|
|
24
|
+
labels: { singular: 'Linked set', plural: 'Linked sets' },
|
|
25
|
+
admin: { hidden: true, group: 'Accounts', useAsTitle: 'label' },
|
|
26
|
+
access: { read: canApprove, create: never, update: never, delete: never },
|
|
27
|
+
fields: [
|
|
28
|
+
// What approvers see where a row names its set: "Started by someone@example.com".
|
|
29
|
+
{ name: 'label', type: 'text', admin: { readOnly: true } },
|
|
30
|
+
{ name: 'requestedBy', type: 'relationship', relationTo: opts.users, admin: { readOnly: true } },
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
const members = {
|
|
34
|
+
slug: MEMBERS,
|
|
35
|
+
labels: { singular: 'Linked account', plural: 'Linked accounts' },
|
|
36
|
+
admin: {
|
|
37
|
+
group: 'Accounts',
|
|
38
|
+
defaultColumns: ['user', 'status', 'link', 'confirmedAt', 'approvedAt'],
|
|
39
|
+
description: 'Accounts that one person asked to link. Approve a confirmed one by setting its status to Approved. You can’t approve a set you belong to. Delete a row to unlink it.',
|
|
40
|
+
},
|
|
41
|
+
access: { read: canApprove, create: never, update: canApprove, delete: canApprove },
|
|
42
|
+
fields: [
|
|
43
|
+
{ name: 'link', type: 'relationship', relationTo: LINKS, required: true, index: true, label: 'Linked set', admin: { readOnly: true, description: 'Filter the list by this set to see every account in it.' } },
|
|
44
|
+
{ name: 'user', type: 'relationship', relationTo: opts.users, required: true, unique: true, admin: { readOnly: true } },
|
|
45
|
+
{
|
|
46
|
+
name: 'status',
|
|
47
|
+
type: 'select',
|
|
48
|
+
required: true,
|
|
49
|
+
defaultValue: 'requested',
|
|
50
|
+
options: [
|
|
51
|
+
{ label: 'Waiting for the email to be confirmed', value: 'requested' },
|
|
52
|
+
{ label: 'Confirmed, waiting for approval', value: 'confirmed' },
|
|
53
|
+
{ label: 'Approved', value: 'approved' },
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
{ name: 'tokenHash', type: 'text', index: true, hidden: true },
|
|
57
|
+
{ name: 'tokenExpires', type: 'date', hidden: true },
|
|
58
|
+
{ name: 'addedBy', type: 'relationship', relationTo: opts.users, admin: { readOnly: true } },
|
|
59
|
+
{ name: 'confirmedAt', type: 'date', admin: { readOnly: true } },
|
|
60
|
+
{ name: 'approvedBy', type: 'relationship', relationTo: opts.users, admin: { readOnly: true } },
|
|
61
|
+
{ name: 'approvedAt', type: 'date', admin: { readOnly: true } },
|
|
62
|
+
],
|
|
63
|
+
hooks: {
|
|
64
|
+
beforeChange: [
|
|
65
|
+
async ({ data, originalDoc, operation, req }) => {
|
|
66
|
+
if (internal(req))
|
|
67
|
+
return data;
|
|
68
|
+
// Outside the plugin's own endpoints, the only change allowed is an approver approving a confirmed account.
|
|
69
|
+
if (operation !== 'update' || !originalDoc)
|
|
70
|
+
throw new APIError('Links are requested from the account page.', 403, undefined, true);
|
|
71
|
+
if (!(await approver(opts, req)))
|
|
72
|
+
throw new APIError('You can’t approve links.', 403, undefined, true);
|
|
73
|
+
const fields = ['link', 'user', 'tokenHash', 'tokenExpires', 'addedBy', 'confirmedAt', 'approvedBy', 'approvedAt'];
|
|
74
|
+
for (const f of fields)
|
|
75
|
+
if (f in data && data[f] !== undefined && String(idOf(data[f] ?? null)) !== String(idOf(originalDoc[f] ?? null)))
|
|
76
|
+
throw new APIError('Only the status can be changed here.', 403, undefined, true);
|
|
77
|
+
if (data.status === originalDoc.status)
|
|
78
|
+
return data;
|
|
79
|
+
if (originalDoc.status !== 'confirmed' || data.status !== 'approved')
|
|
80
|
+
throw new APIError('Only a confirmed account can be approved, and an approval can’t be undone here: delete the row to unlink.', 400, undefined, true);
|
|
81
|
+
const me = req.user;
|
|
82
|
+
const people = [String(me.id), hatsStateOf(me)?.via].filter(Boolean);
|
|
83
|
+
const mine = await req.payload.count({
|
|
84
|
+
collection: MEMBERS,
|
|
85
|
+
where: { and: [{ link: { equals: idOf(originalDoc.link) } }, { user: { in: people } }] },
|
|
86
|
+
overrideAccess: true,
|
|
87
|
+
req,
|
|
88
|
+
});
|
|
89
|
+
if (mine.totalDocs > 0)
|
|
90
|
+
throw new APIError('You can’t approve a set you belong to. Ask another administrator.', 403, undefined, true);
|
|
91
|
+
return { ...data, approvedBy: me.id, approvedAt: new Date().toISOString() };
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
afterChange: [
|
|
95
|
+
async ({ doc, previousDoc, operation, req }) => {
|
|
96
|
+
if (operation === 'update' && previousDoc?.status !== 'approved' && doc.status === 'approved' && !internal(req))
|
|
97
|
+
await opts.onEvent?.({ type: 'link-approved', req, link: idOf(doc.link), account: idOf(doc.user), by: String(req.user.id) });
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
afterDelete: [
|
|
101
|
+
async ({ doc, req }) => {
|
|
102
|
+
const link = idOf(doc.link);
|
|
103
|
+
const account = idOf(doc.user);
|
|
104
|
+
await revokeSessions(req.payload, { and: [{ link: { equals: link } }, { or: [{ user: { equals: account } }, { via: { equals: account } }] }] }, 'unlinked', req);
|
|
105
|
+
if (!internal(req))
|
|
106
|
+
await opts.onEvent?.({ type: 'unlinked', payload: req.payload, link, account, by: req.user ? String(req.user.id) : null });
|
|
107
|
+
if (!req.context?.hatsDissolving)
|
|
108
|
+
await dissolveIfAlone(req.payload, link, req);
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
const sessions = {
|
|
114
|
+
slug: SESSIONS,
|
|
115
|
+
admin: { hidden: true },
|
|
116
|
+
access: { read: never, create: never, update: never, delete: never },
|
|
117
|
+
fields: [
|
|
118
|
+
{ name: 'sid', type: 'text', required: true, unique: true },
|
|
119
|
+
{ name: 'user', type: 'text', required: true, index: true },
|
|
120
|
+
{ name: 'via', type: 'text', index: true },
|
|
121
|
+
{ name: 'link', type: 'text', index: true },
|
|
122
|
+
{ name: 'hat', type: 'text' },
|
|
123
|
+
// Per account: when its second factor was last given in this browser, so switching up is asked again later.
|
|
124
|
+
{ name: 'steppedUp', type: 'json' },
|
|
125
|
+
{ name: 'expiresAt', type: 'date', index: true },
|
|
126
|
+
// Set when the session is ended. Kept so a session Payload puts back by accident stays signed out.
|
|
127
|
+
{ name: 'revokedAt', type: 'date', index: true },
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
return [links, members, sessions];
|
|
131
|
+
}
|