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:
co-authored by
Claude Opus 5.5
parent
1270ebc3d1
commit
de414a81a8
+19
-2
@@ -8,6 +8,21 @@ versions at once, go through every "Requires project changes" section in order,
|
||||
version you have. A new release = a new section at the top; we remove the oldest ones only
|
||||
once there are more than 20.
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Fixes
|
||||
- **Role checks in a client component: import `isAdmin`, `isEditor` and `hasMinimumRole` (and the type `Role`) from
|
||||
`@intecion/ipal-kit/client`.** The advice since 1.16.4 led to importing them from `@intecion/ipal-kit`, which reaches
|
||||
`server-only` modules: `next build --webpack` fails with `'server-only' cannot be imported from a Client Component
|
||||
module`. The main entry keeps exporting them for server code; its Turbopack behaviour is unchanged. access.md also
|
||||
says now what `useConfig()` carries: `admin.user` only, so accounts of `access.staffCollections` need
|
||||
`{ staffCollections: [...] }`.
|
||||
|
||||
### Requires project changes (what projects must update)
|
||||
- **Only if a `'use client'` file imports `isAdmin`, `isEditor` or `hasMinimumRole` from `@intecion/ipal-kit`:**
|
||||
change the import to `@intecion/ipal-kit/client` and keep the second argument (`isAdmin(user, config)`).
|
||||
`grep -rlE "^['\"]use client" src | xargs grep -nE "from '@intecion/ipal-kit'"` lists the files; `import type` may stay.
|
||||
|
||||
## 1.16.6
|
||||
|
||||
> **Read before upgrading — this is not a routine patch.** It turns on a new default for every site with 2FA: an
|
||||
@@ -282,8 +297,10 @@ once there are more than 20.
|
||||
authenticator still works; if it does not, reset that account's 2FA and set it up again.
|
||||
- **`isAdmin` / `isEditor` / `hasMinimumRole` in a client component or in `proxy.ts` / middleware** return `false`
|
||||
unless they are told which collections are staff: `isAdmin(user, config)` with the config from `useConfig()`, or
|
||||
`isAdmin(user, { staffCollections: ['users'] })`. On the server (`isAdmin(req.user)` in hooks, endpoints, access
|
||||
functions) nothing changes; `isAdmin(req.user, req.payload)` is the explicit form.
|
||||
`isAdmin(user, { staffCollections: ['users'] })`. A client component imports them from `@intecion/ipal-kit/client`
|
||||
(corrected later: the main entry, which this note implied, does not build there with webpack; `/client` has them
|
||||
in the version after 1.16.6). On the server (`isAdmin(req.user)` in hooks, endpoints, access functions) nothing
|
||||
changes; `isAdmin(req.user, req.payload)` is the explicit form.
|
||||
- **A second staff collection (`access.staffCollections`) is not covered by 2FA** — the log says so at start.
|
||||
- **Own code that reads a plugin collection or global with `overrideAccess: false`** must pass a `user` from
|
||||
`payload.auth({ headers })`; a user fetched by id and passed by hand is refused when it has TOTP set up, and its
|
||||
|
||||
Reference in New Issue
Block a user