Access defaults overridable; unlock admin-only; 2FA target validated

- access.authAccess merges over the injected auth collection's access;
  unlock is admin-only by default
- access.firstUserAdmin (default true) makes the first-register promotion optional
- globalOverrides: object merges access/admin/hooks, function takes over
- form Emails protection is applied before formOverrides.fields, so a
  project can change it there
- 2FA defaults to admin.user and fails at init when the target is not an
  auth collection or differs from admin.user (twoFactor.allowCollectionMismatch)
- buildRolesField, injectRoles, applyGlobalOverrides exported

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-22 17:23:14 +02:00
co-authored by Claude Opus 5.5
parent 14fd2c497f
commit a87742621a
11 changed files with 334 additions and 65 deletions
+22 -1
View File
@@ -12,6 +12,7 @@ export type TotpPluginFactory = (options: {
forceSetup: boolean
totp: { issuer: string }
}) => Plugin
import type { GlobalOverrides } from './globals/overrides.js'
import type { AccessOption } from './modules/access/types.js'
import type { ContentOption } from './modules/content/types.js'
import type { FormsOption } from './modules/forms/types.js'
@@ -89,6 +90,15 @@ export type IpalOptions = {
*/
pages?: PagesOption
/**
* Change any of the plugin's globals (site-settings, site-integrations,
* cookie-settings, notifications): an object merges over the plugin's
* (`access` / `admin` / `hooks` key by key, your keys win), a function gets
* the global and returns the one to use. E.g. let any logged-in user edit
* Notifications: `{ notifications: { access: { update: authenticated } } }`.
*/
globalOverrides?: GlobalOverrides
/**
* next/cache `revalidatePath`, INJECTED (the plugin never imports next/cache).
* When given, saving any of the plugin's globals (Site Settings, Site
@@ -129,7 +139,18 @@ export type IpalOptions = {
*/
twoFactor?:
| {
/** Auth collection slug. Defaults to 'users'. */
/**
* Let `collectionSlug` differ from the panel's login collection
* (admin.user). Off by default: a mismatch means panel users skip 2FA,
* so the plugin refuses to start. Set true only when you protect a
* second auth collection on purpose.
*/
allowCollectionMismatch?: boolean
/**
* Auth collection TOTP wraps. Default: the panel's login collection —
* admin.user, else the first auth collection (with the one the plugin
* injects). Must be an auth collection.
*/
collectionSlug?: CollectionSlug
/** Name shown in the authenticator app (e.g. company/site name). */
issuer: string