Role checks in client components: export them from /client, fix the docs

access.md and the 1.16.4 upgrade notes led projects to import isAdmin from
'@intecion/ipal-kit' in a client component; with `next build --webpack` that
fails ('server-only' cannot be imported from a Client Component module).
No existing entry had a client-safe one, so '@intecion/ipal-kit/client' now
exports hasMinimumRole, isAdmin, isEditor and the type Role; the main entry
keeps them for server code.

Docs: access.md (snippet with imports, server vs client, useConfig() carries
admin.user only), AGENT.md, ipal-debug, ipal-reference, ipal-upgrade, the
1.16.4 note, an Unreleased changelog entry. Tests: /client reaches no
server-only module, the predicates' answers with a client config, no
client-component example in the docs imports the main entry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-24 22:00:27 +01:00
co-authored by Claude Opus 5.5
parent 1270ebc3d1
commit de414a81a8
13 changed files with 117 additions and 19 deletions
+4
View File
@@ -1,4 +1,8 @@
'use client'
// Role predicates for client components (the main entry reaches 'server-only' modules and does not build
// there with webpack). Concrete file, not the access barrel. On the server import them from the main entry.
export { hasMinimumRole, isAdmin, isEditor } from '../modules/access/predicates.js'
export type { Role } from '../modules/access/types.js'
export { A11Y_DEFAULT_TEXTS, AccessibilityProvider, AccessibilityWidget, useAccessibility } from '../modules/accessibility/client.js'
export type { A11yClassNames, A11yState, A11yTexts } from '../modules/accessibility/client.js'
export { Analytics } from '../modules/analytics/client.js'
+4 -2
View File
@@ -86,7 +86,8 @@ export function staffCollectionSlugs(source?: MaybePayload): string[] {
* - where the staff collections are not known — no source given and ipalKit
* never ran in this bundle (client components, Next middleware, the edge
* runtime) — nobody is staff. Pass the source there: `isAdmin(user, config)`
* with the config from `useConfig()`, or `isAdmin(user, { staffCollections: ['users'] })`.
* with the config from `useConfig()` (client components import from
* '@intecion/ipal-kit/client'), or `isAdmin(user, { staffCollections: ['users'] })`.
*/
function isStaffAccount(user: MaybeUser, source?: MaybePayload): boolean {
if (!user || typeof user !== 'object') {return false}
@@ -117,7 +118,8 @@ function highestRoleIndex(user: MaybeUser): number {
* functions, hooks, endpoints); without it the staff collections of the
* config ipalKit built in this process are used — and where there is none
* (a browser bundle, middleware) the answer is false: pass the config from
* `useConfig()` or `{ staffCollections: ['users'] }` there.
* `useConfig()` or `{ staffCollections: ['users'] }` there. A client component
* imports it from '@intecion/ipal-kit/client': the main entry does not build there with webpack.
*/
export function hasMinimumRole(user: MaybeUser, minimum: Role, payload?: MaybePayload): boolean {
if (!isStaffAccount(user, payload)) {return false}