@clocklimited/payload-2fa's admin provider reads the current path from an x-pathname request header. Nothing sets it on /admin (the createProxy matcher skips /admin), so the path was null: every admin page, the setup screen too, redirected to /admin/setup-totp?back=null, forever. Every new admin on a site with 2FA got stuck. ipalKit now swaps that provider for its own TotpRedirectProvider (@intecion/ipal-kit/admin, client-side): it reads the path in the browser, never redirects away from the setup/verify screens or logout, and renders nothing while redirecting. twoFactor.provider takes a project component, or false to keep the package's. totpRedirectTarget / totpAdminPath export the rules. Projects run generate:importmap. Test: test/totpRedirect.test.ts (redirect walk, provider swap). Dev app: IPAL_DEV_2FA=1 turns 2FA on. Docs: security.md, CHANGELOG (Unreleased), AGENT.md, ipal-setup/-upgrade/-debug/-reference, PROGRAMISTA item 51. Co-Authored-By: Claude Opus 5.5 <[email protected]>
90 lines
2.6 KiB
TypeScript
90 lines
2.6 KiB
TypeScript
import { payloadTotp } from '@clocklimited/payload-2fa'
|
|
import { sqliteAdapter } from '@payloadcms/db-sqlite'
|
|
import { lexicalEditor } from '@payloadcms/richtext-lexical'
|
|
import { ipalKit } from '../src/index.js'
|
|
import path from 'path'
|
|
import { buildConfig } from 'payload'
|
|
import sharp from 'sharp'
|
|
import { fileURLToPath } from 'url'
|
|
|
|
import { testEmailAdapter } from './helpers/testEmailAdapter.js'
|
|
import { i18nConfig } from './i18n.config.js'
|
|
import { seed } from './seed.js'
|
|
|
|
const filename = fileURLToPath(import.meta.url)
|
|
const dirname = path.dirname(filename)
|
|
|
|
if (!process.env.ROOT_DIR) {
|
|
process.env.ROOT_DIR = dirname
|
|
}
|
|
|
|
export default buildConfig({
|
|
admin: {
|
|
importMap: {
|
|
baseDir: path.resolve(dirname),
|
|
},
|
|
},
|
|
collections: [
|
|
{
|
|
slug: 'users',
|
|
auth: true,
|
|
fields: [],
|
|
},
|
|
{
|
|
slug: 'pages',
|
|
fields: [
|
|
{ name: 'title', type: 'text', localized: true },
|
|
{ name: 'slug', type: 'text', index: true, localized: true },
|
|
{
|
|
name: 'layout',
|
|
type: 'blocks',
|
|
blocks: [{ slug: 'formBlock', fields: [{ name: 'form', type: 'relationship', relationTo: 'forms' }] }],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
slug: 'posts',
|
|
fields: [{ name: 'title', type: 'text' }],
|
|
},
|
|
{
|
|
slug: 'media',
|
|
fields: [],
|
|
upload: { staticDir: path.resolve(dirname, 'media') },
|
|
},
|
|
],
|
|
|
|
db: sqliteAdapter({
|
|
client: {
|
|
url: process.env.DATABASE_URI || 'file:./payload.db',
|
|
},
|
|
}),
|
|
editor: lexicalEditor(),
|
|
email: testEmailAdapter,
|
|
onInit: async (payload) => {
|
|
await seed(payload)
|
|
},
|
|
plugins: [
|
|
ipalKit({
|
|
access: { authCollection: 'users' },
|
|
i18n: i18nConfig,
|
|
consentLog: true,
|
|
// Cookie review + "Crawl site" (needs IPAL_COOKIE_SCAN_URL / IPAL_COOKIE_SCAN_TOKEN and a running services/cookie-crawler).
|
|
cookieScanner: { crawl: true },
|
|
forms: {},
|
|
seo: { collections: ['posts', 'pages'] },
|
|
stats: true,
|
|
// 2FA is enforced by default; the dev sandbox opts out so it boots without an authenticator.
|
|
// IPAL_DEV_2FA=1 turns it on (first-login setup and verify screens).
|
|
twoFactor: process.env.IPAL_DEV_2FA ? { issuer: 'ipal-kit dev', plugin: payloadTotp } : false,
|
|
}),
|
|
],
|
|
secret: process.env.PAYLOAD_SECRET || 'test-secret_key',
|
|
sharp,
|
|
typescript: {
|
|
// Payload's dev init spawns `payload generate:types` on every start/recompile and never
|
|
// reaps it, so each restart left an orphan. Run `pnpm generate:types` when types change.
|
|
autoGenerate: false,
|
|
outputFile: path.resolve(dirname, 'payload-types.ts'),
|
|
},
|
|
})
|