2FA fixed

This commit is contained in:
2026-10-15 22:24:28 +02:00
parent eb436528d4
commit bd2fbaf8bf
16 changed files with 808 additions and 208 deletions
Regular → Executable
View File
-10
View File
@@ -1,10 +0,0 @@
import type { Field } from 'payload';
/**
* Cloudflare R2 storage credentials.
* Reserved for future use — media offloading to R2.
*
* Protected at the global level (SiteIntegrations requires an authenticated
* user), so the access keys stay editable in the admin panel while remaining
* inaccessible to anonymous API requests.
*/
export declare const storageFields: Field[];
-43
View File
@@ -1,43 +0,0 @@
/**
* Cloudflare R2 storage credentials.
* Reserved for future use — media offloading to R2.
*
* Protected at the global level (SiteIntegrations requires an authenticated
* user), so the access keys stay editable in the admin panel while remaining
* inaccessible to anonymous API requests.
*/ export const storageFields = [
{
name: 'r2Bucket',
type: 'text',
admin: {
description: 'R2 bucket name.'
}
},
{
name: 'r2Endpoint',
type: 'text',
admin: {
description: 'R2 S3-compatible endpoint URL.'
}
},
{
name: 'r2AccessKeyId',
type: 'text',
admin: {
description: 'R2 access key ID.'
}
},
{
name: 'r2SecretAccessKey',
type: 'text',
admin: {
description: 'R2 secret access key.',
// Masked in the UI (••••) — stored plaintext, readable for R2 auth.
components: {
Field: '@intecion/ipal-kit/client#MaskedField'
}
}
}
];
//# sourceMappingURL=storage.js.map
-1
View File
@@ -1 +0,0 @@
{"version":3,"sources":["../../../../src/globals/SiteIntegrations/fields/storage.ts"],"sourcesContent":["import type { Field } from 'payload'\n\n/**\n * Cloudflare R2 storage credentials.\n * Reserved for future use — media offloading to R2.\n *\n * Protected at the global level (SiteIntegrations requires an authenticated\n * user), so the access keys stay editable in the admin panel while remaining\n * inaccessible to anonymous API requests.\n */\nexport const storageFields: Field[] = [\n {\n name: 'r2Bucket',\n type: 'text',\n admin: {\n description: 'R2 bucket name.',\n },\n },\n {\n name: 'r2Endpoint',\n type: 'text',\n admin: {\n description: 'R2 S3-compatible endpoint URL.',\n },\n },\n {\n name: 'r2AccessKeyId',\n type: 'text',\n admin: {\n description: 'R2 access key ID.',\n },\n },\n {\n name: 'r2SecretAccessKey',\n type: 'text',\n admin: {\n description: 'R2 secret access key.',\n // Masked in the UI (••••) — stored plaintext, readable for R2 auth.\n components: {\n Field: '@intecion/ipal-kit/client#MaskedField',\n },\n },\n },\n]\n"],"names":["storageFields","name","type","admin","description","components","Field"],"mappings":"AAEA;;;;;;;CAOC,GACD,OAAO,MAAMA,gBAAyB;IACpC;QACEC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aAAa;QACf;IACF;IACA;QACEH,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aAAa;QACf;IACF;IACA;QACEH,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aAAa;QACf;IACF;IACA;QACEH,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aAAa;YACb,oEAAoE;YACpEC,YAAY;gBACVC,OAAO;YACT;QACF;IACF;CACD,CAAA"}
-76
View File
@@ -1,76 +0,0 @@
/*
* Starter stylesheet for a sitemap served via buildSitemapXml({ cssUrl }).
* Uses type="text/css" on XML (W3C "Associating Style Sheets with XML") — NOT
* XSLT, so no browser deprecation warning. Selectors are the XML tag names.
*
* Copy to your project's /public/sitemap.css and adjust colors/spacing to taste.
* Crawlers ignore this; it only affects the human-readable browser view.
*/
urlset {
display: block;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: #090d16;
color: #f1f5f9;
padding: 2rem 1.5rem;
max-width: 1200px;
margin: 0 auto;
line-height: 1.5;
}
/* Each URL entry as a card. */
url {
display: block;
background: #111827;
border: 1px solid #1e293b;
border-radius: 8px;
padding: 1rem 1.25rem;
margin-bottom: 0.75rem;
}
/* The URL itself. */
loc {
display: block;
font-size: 0.95rem;
font-weight: 600;
color: #f97316;
margin-bottom: 0.5rem;
word-break: break-all;
}
/* Metadata line: lastmod / changefreq / priority, each with a label. */
lastmod,
changefreq,
priority {
display: inline-block;
font-size: 0.8rem;
color: #94a3b8;
margin-right: 1.5rem;
}
lastmod::before {
content: 'Ostatnia modyfikacja: ';
color: #64748b;
}
changefreq::before {
content: 'Częstotliwość: ';
color: #64748b;
}
priority::before {
content: 'Priorytet: ';
color: #64748b;
}
/* hreflang alternates as small pills. */
link {
display: inline-block;
font-size: 0.75rem;
background: #1e293b;
color: #38bdf8;
border: 1px solid #334155;
padding: 0.15rem 0.45rem;
border-radius: 4px;
margin: 0.4rem 0.35rem 0 0;
}
+6 -5
View File
@@ -69,16 +69,17 @@ import { testEmailEndpoint } from './modules/email/test/testEmailEndpoint.js';
// '@clocklimited/payload-2fa'" crashing even public frontend pages).
let totp = tf.plugin;
if (!totp) {
// Fallback: dynamic import. Variable specifier dodges the plugin's own
// TS2307, but Next may NOT trace it into the server bundle — projects
// using this path MUST add '@clocklimited/payload-2fa' to
// serverExternalPackages in next.config (see docs/security.md).
// Fallback: dynamic import, resolvable because the package is an optional
// peer. Variable specifier dodges the plugin's own TS2307. Works only
// outside Next (payload CLI): webpack turns it into an empty context, and
// serverExternalPackages fails on the package's own .css imports — in
// Next the project MUST inject `plugin` (see docs/security.md).
try {
const pkg = '@clocklimited/payload-2fa';
const mod = await import(pkg);
totp = mod.payloadTotp ?? mod.totpPlugin;
} catch (err) {
throw new Error('[ipal] 2FA is enforced but @clocklimited/payload-2fa could not be loaded. ' + 'Best fix — inject it: `import { payloadTotp } from "@clocklimited/payload-2fa"` ' + 'then `twoFactor: { issuer, plugin: payloadTotp }`. Or install it AND add ' + "'@clocklimited/payload-2fa' to serverExternalPackages in next.config. Or set " + `twoFactor: false to opt out (discouraged). Original error: ${String(err)}`);
throw new Error('[ipal] 2FA is enforced but @clocklimited/payload-2fa could not be loaded. ' + 'Inject it (required in Next): `import { payloadTotp } from "@clocklimited/payload-2fa"` ' + 'then `twoFactor: { issuer, plugin: payloadTotp }`. Adding it to ' + 'serverExternalPackages does NOT help (the package imports .css). Or set ' + `twoFactor: false to opt out (discouraged). Original error: ${String(err)}`);
}
}
if (typeof totp !== 'function') {
+1 -1
View File
File diff suppressed because one or more lines are too long
+15 -12
View File
@@ -1,10 +1,13 @@
import type { Field, Plugin } from 'payload';
import type { CollectionSlug, Field, Plugin } from 'payload';
/**
* Factory shape of @clocklimited/payload-2fa's `payloadTotp` export — injected
* so the plugin never imports the optional peer itself.
* so the plugin never imports the optional peer itself. `collection` is
* `CollectionSlug` (not `string`): payloadTotp requires it, and in a project
* with generated payload-types it's a narrowed union — `string` would make
* `plugin: payloadTotp` fail to type-check.
*/
export type TotpPluginFactory = (options: {
collection: string;
collection: CollectionSlug;
forceSetup: boolean;
totp: {
issuer: string;
@@ -79,19 +82,19 @@ export type IpalOptions = {
*/
twoFactor?: {
/** Auth collection slug. Defaults to 'users'. */
collectionSlug?: string;
collectionSlug?: CollectionSlug;
/** Name shown in the authenticator app (e.g. company/site name). */
issuer: string;
/**
* The 2FA plugin factory, INJECTED from the project:
* `import { payloadTotp } from '@clocklimited/payload-2fa'`. Strongly
* recommended — injecting it (the same pattern as NextResponse /
* revalidatePath) means the plugin never dynamically imports the
* optional peer, which Next can fail to bundle into the server chunks
* ("Cannot find module '@clocklimited/payload-2fa'" at runtime, even on
* public frontend pages). If omitted, the plugin falls back to a dynamic
* import and you MUST add '@clocklimited/payload-2fa' to
* serverExternalPackages in next.config. See docs/security.md.
* `import { payloadTotp } from '@clocklimited/payload-2fa'`. REQUIRED in
* Next — injecting it (the same pattern as NextResponse / revalidatePath)
* means the plugin never dynamically imports the optional peer, which
* Next can't bundle ("Cannot find module '@clocklimited/payload-2fa'",
* even on public frontend pages). serverExternalPackages is no fix: the
* package imports its own .css, which Node can't load. If omitted, the
* plugin falls back to a dynamic import — works only outside Next
* (payload CLI). See docs/security.md.
*/
plugin?: TotpPluginFactory;
} | false;
+1 -1
View File
File diff suppressed because one or more lines are too long
+3 -1
View File
@@ -37,7 +37,8 @@ tej procedury. Pytasz tylko, gdy brakuje czegoś, czego nie możesz uzyskać sam
| `TS2307 next/navigation` w `dist` pluginu | import bez `.js` w kliencie pluginu (NodeNext) | **bug ipal-kit** → plugin-gap; plugin importuje `'next/navigation.js'` |
| `TS2307 @payloadcms/storage-s3` | brak pakietu przy `buildR2Storage` | `pnpm add @payloadcms/storage-s3` + `buildR2Storage(['media'], { s3Storage })` |
| `does not provide an export named X` / `X is not a function` | symbol nie wyeksportowany z entry pointu albo zły subpath (`/client` vs root vs `/server` vs `/rsc`) | `docs/README.md` → właściwy import; brak w każdym entry → **bug ipal-kit** (eksport) |
| `Cannot find module '@clocklimited/payload-2fa'` | brak wstrzyknięcia | `twoFactor: { plugin: payloadTotp }` |
| `Cannot find module '@clocklimited/payload-2fa'` | brak wstrzyknięcia | `twoFactor: { plugin: payloadTotp }` (`serverExternalPackages` nie pomaga — pada na `.css`) |
| `TS2322` przy `plugin: payloadTotp` (`string` vs `CollectionSlug`) | ipal-kit ≤ 1.8.13 typował `collection` jako `string` | zaktualizuj ipal-kit; usuń adapter/rzutowanie |
| `Page changed from static to dynamic at runtime` | `headers()`, `cookies()`, `searchParams` w drzewie strony (często `not-found.tsx`) | locale z `params`; `not-found` → `LocaleView` (pages.md); `headers()` tylko w server actions / route handlers |
| trasy `ƒ` mimo `generateStaticParams` | build nie widzi bazy | `DATABASE_URI` w buildzie (PROGRAMISTA §4.3) |
| build pada `ENOTFOUND` / Mongoose | trasa czyta bazę w buildzie bez bazy | sitemap/robots/llms: `export const dynamic = 'force-dynamic'` (tylko one) |
@@ -85,6 +86,7 @@ tej procedury. Pytasz tylko, gdy brakuje czegoś, czego nie możesz uzyskać sam
|---|---|---|
| zmiana w pluginie niewidoczna | stara wersja w `node_modules` / `.next` | `pnpm add @intecion/ipal-kit@<wersja>`, `grep -c <symbol> node_modules/@intecion/ipal-kit/dist/...`, `rm -rf .next`, restart |
| skille nieaktualne po aktualizacji | nie odświeżone | `pnpm exec ipal-skills` |
| `ipal-skills: command not found` | ipal-kit ≤ 1.8.13 nie publikował `bin` | zaktualizuj ipal-kit |
| „Kod dobry, zachowanie złe” | — | po kolei: restart dev → Save w panelu → dublet zależności → importmap → cache |
## Kiedy to bug ipal-kit (raport, nie łatka w node_modules)
+3 -1
View File
@@ -480,6 +480,7 @@ Rób po jednej pozycji, buduj, sprawdzaj. Kolejność wg wagi:
| 12 | Skrypty firm trzecich bez zgody | `ConsentScript` / `Analytics` | consent.md, analytics.md |
| 13 | Brak health checku | `createHealthRoute` (§2.8) | — |
| 14 | 2FA crash „Cannot find module” | wstrzyknij `plugin: payloadTotp` | security.md |
| 14a | obejścia z ≤ 1.8.13: adapter `payloadTotp` z rzutowaniem na `CollectionSlug`, `'@clocklimited/payload-2fa'` w `serverExternalPackages` | usuń — `plugin: payloadTotp` wprost, bez wpisu w `next.config` | security.md |
| 15 | Pola `ctaLabel`/`pdfUrl`, sekcje-monolity | refaktor wg AGENT.md §6.7 (z migracją danych!) | AGENT.md |
| 15a | `buildR2Storage(['media'])` bez adaptera (od 1.8.1 błąd przy env R2) | `pnpm add @payloadcms/storage-s3`, `buildR2Storage(['media'], { s3Storage })` | storage.md |
| 15b | `src/fields/link.ts`, `src/lib/links.ts` w projekcie | importy z pluginu, usuń kopie (bez migracji bazy) | links.md |
@@ -511,7 +512,8 @@ Po aktualizacji pakietu: `pnpm ipal:skills` (nowe wersje skilli), `pnpm payload
| Pusty tab SEO, brak kolekcji Forms | rozjazd wersji `@payloadcms/*` — `pnpm.overrides` |
| `PayloadComponent not found in importMap` | `pnpm payload generate:importmap` |
| `Cannot destructure property 'config'` | dublet `@payloadcms/ui` w pluginie — `ls node_modules/@intecion/ipal-kit/node_modules/@payloadcms/ui` |
| `Cannot find module '@clocklimited/payload-2fa'` | wstrzyknij `plugin: payloadTotp` w `twoFactor` |
| `Cannot find module '@clocklimited/payload-2fa'` | wstrzyknij `plugin: payloadTotp` w `twoFactor` (`serverExternalPackages` nie pomaga) |
| `TS2322` przy `plugin: payloadTotp` / `ipal-skills: command not found` | ipal-kit ≤ 1.8.13 — zaktualizuj |
| `[ipal] R2 storage: … adapter was not injected` | `pnpm add @payloadcms/storage-s3` + `buildR2Storage(['media'], { s3Storage })` |
| Baner bez stylów | brak Tailwinda albo `@source` na plugin |
| `/admin`, `/_next` → 500 | matcher proxy nie jest literałem inline |
+12 -14
View File
@@ -263,7 +263,7 @@ Uwaga: pakiet nie ma jeszcze stabilnego 3.0.0 — użyj konkretnej wersji beta
(albo `^3.0.0-0`, żeby dopuścić prereleasy). Sam `^3.0.0` da błąd
ERR_PNPM_NO_MATCHING_VERSION.
### Konfiguracja (payload.config.ts) — WSTRZYKNIJ plugin (zalecane)
### Konfiguracja (payload.config.ts) — WSTRZYKNIJ plugin (wymagane w Next)
```ts
import { payloadTotp } from '@clocklimited/payload-2fa'
@@ -280,20 +280,18 @@ ipalKit({
**Dlaczego `plugin: payloadTotp` (wstrzyknięcie):** to ten sam wzorzec co
`NextResponse`/`revalidatePath` — projekt podaje peer-dep, plugin go NIE
importuje. Bez tego plugin robi dynamiczny import, którego **Next potrafi nie
wbundlować** do server chunks → błąd runtime **„Cannot find module
'@clocklimited/payload-2fa'"** lecący nawet na publicznych stronach frontu.
Wstrzyknięcie eliminuje ten problem u źródła.
importuje. Bez tego plugin robi dynamiczny import, którego **Next nie
wbundluje** (webpack zamienia import ze zmiennej w pusty kontekst) → błąd
**„Cannot find module '@clocklimited/payload-2fa'"** w `next build` i na każdej
stronie (także publicznej). Build potrafi przy tym przejść „na zielono", bo
`generateStaticParams` łapie błąd — strona jest zepsuta dopiero w runtime.
**Jeśli NIE wstrzykujesz** (zostawiasz dynamiczny import) — MUSISZ dodać pakiet do
`serverExternalPackages` w `next.config`, żeby Next nie próbował go bundlować:
```ts
// next.config.ts
const nextConfig = {
serverExternalPackages: ['@clocklimited/payload-2fa'],
}
```
**`serverExternalPackages` NIE jest obejściem.** Pakiet importuje własne
`*.module.css`; po externalizacji ładuje go Node, który nie zna `.css` →
`ERR_UNKNOWN_FILE_EXTENSION` przy zbieraniu danych `/admin`. Jedyna działająca
konfiguracja w Next to wstrzyknięcie. Dynamiczny import zostaje tylko dla
kontekstów bez Next (CLI `payload …`), gdzie pakiet rozwiązuje się jako opcjonalny
peer ipal-kit.
Plugin ustawia `forceSetup: true` — każdy użytkownik MUSI skonfigurować TOTP po
zalogowaniu. Nie ma opcji „włącz/wyłącz" dla użytkownika.
+9 -1
View File
@@ -42,9 +42,13 @@
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"bin": {
"ipal-skills": "./bin/ipal-skills.mjs"
},
"files": [
"dist",
"docs"
"docs",
"bin"
],
"scripts": {
"build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
@@ -71,6 +75,7 @@
"slugify": "^1.6.6"
},
"peerDependencies": {
"@clocklimited/payload-2fa": "^3.0.0-0",
"@payloadcms/plugin-form-builder": "^3.90.2",
"@payloadcms/plugin-seo": "^3.90.2",
"@payloadcms/richtext-lexical": "^3.90.2",
@@ -132,6 +137,9 @@
]
},
"peerDependenciesMeta": {
"@clocklimited/payload-2fa": {
"optional": true
},
"@payloadcms/storage-s3": {
"optional": true
}
+735 -23
View File
File diff suppressed because it is too large Load Diff
+8 -7
View File
@@ -78,10 +78,11 @@ export const ipalKit = (options: IpalOptions): Plugin => {
let totp: TotpPluginFactory | undefined = tf.plugin
if (!totp) {
// Fallback: dynamic import. Variable specifier dodges the plugin's own
// TS2307, but Next may NOT trace it into the server bundle — projects
// using this path MUST add '@clocklimited/payload-2fa' to
// serverExternalPackages in next.config (see docs/security.md).
// Fallback: dynamic import, resolvable because the package is an optional
// peer. Variable specifier dodges the plugin's own TS2307. Works only
// outside Next (payload CLI): webpack turns it into an empty context, and
// serverExternalPackages fails on the package's own .css imports — in
// Next the project MUST inject `plugin` (see docs/security.md).
try {
const pkg = '@clocklimited/payload-2fa'
const mod = (await import(pkg)) as {
@@ -92,9 +93,9 @@ export const ipalKit = (options: IpalOptions): Plugin => {
} catch (err) {
throw new Error(
'[ipal] 2FA is enforced but @clocklimited/payload-2fa could not be loaded. ' +
'Best fix — inject it: `import { payloadTotp } from "@clocklimited/payload-2fa"` ' +
'then `twoFactor: { issuer, plugin: payloadTotp }`. Or install it AND add ' +
"'@clocklimited/payload-2fa' to serverExternalPackages in next.config. Or set " +
'Inject it (required in Next): `import { payloadTotp } from "@clocklimited/payload-2fa"` ' +
'then `twoFactor: { issuer, plugin: payloadTotp }`. Adding it to ' +
'serverExternalPackages does NOT help (the package imports .css). Or set ' +
`twoFactor: false to opt out (discouraged). Original error: ${String(err)}`,
)
}
+15 -12
View File
@@ -1,11 +1,14 @@
import type { Field, Plugin } from 'payload'
import type { CollectionSlug, Field, Plugin } from 'payload'
/**
* Factory shape of @clocklimited/payload-2fa's `payloadTotp` export — injected
* so the plugin never imports the optional peer itself.
* so the plugin never imports the optional peer itself. `collection` is
* `CollectionSlug` (not `string`): payloadTotp requires it, and in a project
* with generated payload-types it's a narrowed union — `string` would make
* `plugin: payloadTotp` fail to type-check.
*/
export type TotpPluginFactory = (options: {
collection: string
collection: CollectionSlug
forceSetup: boolean
totp: { issuer: string }
}) => Plugin
@@ -90,19 +93,19 @@ export type IpalOptions = {
twoFactor?:
| {
/** Auth collection slug. Defaults to 'users'. */
collectionSlug?: string
collectionSlug?: CollectionSlug
/** Name shown in the authenticator app (e.g. company/site name). */
issuer: string
/**
* The 2FA plugin factory, INJECTED from the project:
* `import { payloadTotp } from '@clocklimited/payload-2fa'`. Strongly
* recommended — injecting it (the same pattern as NextResponse /
* revalidatePath) means the plugin never dynamically imports the
* optional peer, which Next can fail to bundle into the server chunks
* ("Cannot find module '@clocklimited/payload-2fa'" at runtime, even on
* public frontend pages). If omitted, the plugin falls back to a dynamic
* import and you MUST add '@clocklimited/payload-2fa' to
* serverExternalPackages in next.config. See docs/security.md.
* `import { payloadTotp } from '@clocklimited/payload-2fa'`. REQUIRED in
* Next — injecting it (the same pattern as NextResponse / revalidatePath)
* means the plugin never dynamically imports the optional peer, which
* Next can't bundle ("Cannot find module '@clocklimited/payload-2fa'",
* even on public frontend pages). serverExternalPackages is no fix: the
* package imports its own .css, which Node can't load. If omitted, the
* plugin falls back to a dynamic import — works only outside Next
* (payload CLI). See docs/security.md.
*/
plugin?: TotpPluginFactory
}