Fixed 2fa and white-label

This commit is contained in:
2026-10-12 13:10:34 +02:00
parent 13d669b757
commit 78e2f8fc7f
14 changed files with 322 additions and 161 deletions
+19 -12
View File
@@ -17,29 +17,36 @@
* set, nothing is forced.
*/
type BrandingProps = {
/** SiteSettings global slug. Default 'site-settings'. */
settingsSlug?: string;
/** Field holding the site name. Default 'siteName'. */
nameField?: string;
/** Upload field to render as the image. Default 'logo' (Logo) / 'favicon' (Icon). */
imageField?: string;
/** Field holding the site name. Default 'siteName'. */
nameField?: string;
/** SiteSettings global slug. Default 'site-settings'. */
settingsSlug?: string;
};
/** Admin panel logo (login screen + nav). SiteSettings `logo`, falls back to `siteName`. */
/**
* Admin panel logo — this is the LARGE logo on the login / unauthorized screens
* (Payload uses `graphics.Icon` for the small nav glyph). SiteSettings `logo`,
* falls back to `siteName` text. Sized generously for the login screen.
*/
export declare function AdminLogo(props?: BrandingProps): Promise<import("react/jsx-runtime").JSX.Element | null>;
/** Admin panel icon (small nav glyph). SiteSettings `favicon`, falls back to initials. */
export declare function AdminIcon(props?: BrandingProps): Promise<import("react/jsx-runtime").JSX.Element | null>;
/**
* Discreet vendor credit shown at the bottom of the admin nav: "Technology by
* Intecion.com". This is the PLUGIN VENDOR's credit (Intecion ships ipal-kit),
* not client data — so a sensible default here is fine and A0-safe. The client's
* own brand still owns the logo/name above (AdminLogo); this is a small line
* stating who provides the technology. Text/URL overridable; turn it off with
* `whiteLabel: { credit: false }`.
* Discreet vendor credit: "Technology supported by Intecion.com". This is the
* PLUGIN VENDOR's credit (Intecion ships ipal-kit, the framework), not client
* data — a sensible default here is fine and A0-safe. The client's own brand
* still owns the logo/name; this is a small line stating who supports the tech.
* Text/URL overridable; turn it off with `whiteLabel: { credit: false }`.
*
* Wired by ipalKit into admin.components.afterNavLinks.
* Wired by ipalKit into admin.components.afterNavLinks (nav) AND afterLogin
* (login screen footer). `variant` adjusts placement:
* - 'nav' → left-aligned line under the nav links
* - 'login' → centered line below the login form
*/
export declare function IntecionCredit(props?: {
text?: string;
url?: string;
variant?: 'login' | 'nav';
}): import("react/jsx-runtime").JSX.Element;
export {};
+63 -42
View File
@@ -3,8 +3,8 @@ import { getPayload } from 'payload';
async function loadBranding(settingsSlug, nameField, imageField) {
try {
// Consumer alias — resolved in the project's build, hidden from plugin tsc.
// @ts-ignore
const mod = await import('@payload-config');
const spec = '@payload-config';
const mod = await import(spec);
const payload = await getPayload({
config: mod.default
});
@@ -26,76 +26,97 @@ async function loadBranding(settingsSlug, nameField, imageField) {
};
}
}
/** Admin panel logo (login screen + nav). SiteSettings `logo`, falls back to `siteName`. */ export async function AdminLogo(props = {}) {
const { settingsSlug = 'site-settings', nameField = 'siteName', imageField = 'logo' } = props;
/**
* Admin panel logo — this is the LARGE logo on the login / unauthorized screens
* (Payload uses `graphics.Icon` for the small nav glyph). SiteSettings `logo`,
* falls back to `siteName` text. Sized generously for the login screen.
*/ export async function AdminLogo(props = {}) {
const { imageField = 'logo', nameField = 'siteName', settingsSlug = 'site-settings' } = props;
const { name, url } = await loadBranding(settingsSlug, nameField, imageField);
if (url) {
return /*#__PURE__*/ _jsx("img", {
src: url,
alt: name ?? '',
src: url,
style: {
maxHeight: 60,
maxWidth: 240,
width: 'auto',
height: 'auto'
height: 'auto',
maxHeight: 120,
maxWidth: 420,
width: 'auto'
}
});
}
if (name) return /*#__PURE__*/ _jsx("div", {
style: {
fontSize: '1.5rem',
fontWeight: 600
},
children: name
});
if (name) {
return /*#__PURE__*/ _jsx("div", {
style: {
fontSize: '2rem',
fontWeight: 600
},
children: name
});
}
return null // nothing configured → Payload's default
;
}
/** Admin panel icon (small nav glyph). SiteSettings `favicon`, falls back to initials. */ export async function AdminIcon(props = {}) {
const { settingsSlug = 'site-settings', nameField = 'siteName', imageField = 'favicon' } = props;
const { imageField = 'favicon', nameField = 'siteName', settingsSlug = 'site-settings' } = props;
const { name, url } = await loadBranding(settingsSlug, nameField, imageField);
if (url) {
return /*#__PURE__*/ _jsx("img", {
src: url,
alt: name ?? '',
src: url,
style: {
height: 'auto',
maxHeight: 28,
maxWidth: 28,
width: 'auto',
height: 'auto'
width: 'auto'
}
});
}
if (name) return /*#__PURE__*/ _jsx("div", {
style: {
fontWeight: 700
},
children: name.slice(0, 2).toUpperCase()
});
if (name) {
return /*#__PURE__*/ _jsx("div", {
style: {
fontWeight: 700
},
children: name.slice(0, 2).toUpperCase()
});
}
return null;
}
/**
* Discreet vendor credit shown at the bottom of the admin nav: "Technology by
* Intecion.com". This is the PLUGIN VENDOR's credit (Intecion ships ipal-kit),
* not client data — so a sensible default here is fine and A0-safe. The client's
* own brand still owns the logo/name above (AdminLogo); this is a small line
* stating who provides the technology. Text/URL overridable; turn it off with
* `whiteLabel: { credit: false }`.
* Discreet vendor credit: "Technology supported by Intecion.com". This is the
* PLUGIN VENDOR's credit (Intecion ships ipal-kit, the framework), not client
* data — a sensible default here is fine and A0-safe. The client's own brand
* still owns the logo/name; this is a small line stating who supports the tech.
* Text/URL overridable; turn it off with `whiteLabel: { credit: false }`.
*
* Wired by ipalKit into admin.components.afterNavLinks.
* Wired by ipalKit into admin.components.afterNavLinks (nav) AND afterLogin
* (login screen footer). `variant` adjusts placement:
* - 'nav' → left-aligned line under the nav links
* - 'login' → centered line below the login form
*/ export function IntecionCredit(props = {}) {
const { text = 'Technology by Intecion.com', url = 'https://intecion.com' } = props;
const { text = 'Technology supported by Intecion.com', url = 'https://intecion.com', variant = 'nav' } = props;
const style = variant === 'login' ? {
color: 'inherit',
display: 'block',
fontSize: '0.75rem',
marginTop: '2rem',
opacity: 0.6,
padding: '0.5rem',
textAlign: 'center',
textDecoration: 'none'
} : {
color: 'inherit',
display: 'block',
fontSize: '0.75rem',
opacity: 0.6,
padding: '0.75rem 1rem',
textDecoration: 'none'
};
return /*#__PURE__*/ _jsx("a", {
href: url,
target: "_blank",
rel: "noopener noreferrer",
style: {
display: 'block',
padding: '0.75rem 1rem',
fontSize: '0.75rem',
opacity: 0.6,
textDecoration: 'none'
},
style: style,
target: "_blank",
children: text
});
}
File diff suppressed because one or more lines are too long
+41 -22
View File
@@ -62,29 +62,35 @@ import { buildSeoPlugin, injectAutoFillMeta, injectSeoTabs } from './modules/seo
if (!tf?.issuer) {
throw new Error('[ipal] twoFactor.issuer is required (name shown in the authenticator ' + 'app). Pass twoFactor: { issuer: "Your Site" }, or twoFactor: false to ' + 'opt out (discouraged).');
}
try {
// Dynamic specifier via a variable so TS doesn't try to resolve this
// optional peer dependency at build time (it isn't in the plugin's own
// node_modules). Avoids TS2307 without @ts-expect-error; the module
// exists at runtime in projects that installed it.
// @ts-ignore
const mod = await import('@clocklimited/payload-2fa');
// The package exports `payloadTotp`; older/other builds may use
// `totpPlugin`. Accept either so a rename doesn't break us.
const totp = mod.payloadTotp ?? mod.totpPlugin;
if (typeof totp !== 'function') {
throw new Error('expected export payloadTotp (or totpPlugin) to be a function — ' + 'check the installed @clocklimited/payload-2fa version');
// Prefer the INJECTED plugin factory (recommended): the project imports
// payloadTotp from @clocklimited/payload-2fa and passes it in. Then the
// plugin never imports the optional peer itself — no dynamic import, so
// Next can't fail to bundle it (the cause of "Cannot find module
// '@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).
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)}`);
}
config = await totp({
collection: tf.collectionSlug ?? 'users',
forceSetup: true,
totp: {
issuer: tf.issuer
}
})(config);
} catch (err) {
throw new Error('[ipal] 2FA is enforced but @clocklimited/payload-2fa is not installed. ' + 'Run: pnpm add @clocklimited/payload-2fa — or set twoFactor: false to ' + `opt out (discouraged). Original error: ${String(err)}`);
}
if (typeof totp !== 'function') {
throw new Error('[ipal] 2FA: expected payloadTotp (or totpPlugin) to be a function — check the ' + 'injected `plugin` or the installed @clocklimited/payload-2fa version.');
}
config = await totp({
collection: tf.collectionSlug ?? 'users',
forceSetup: true,
totp: {
issuer: tf.issuer
}
})(config);
}
// --- white-label admin branding ---
// Inject admin.components.graphics.Logo/Icon pointing at the plugin's
@@ -139,11 +145,24 @@ import { buildSeoPlugin, injectAutoFillMeta, injectSeoTabs } from './modules/seo
}
},
...creditOn ? {
afterLogin: [
...config.admin?.components?.afterLogin ?? [],
{
path: '@intecion/ipal-kit/admin#IntecionCredit',
serverProps: {
...creditProps,
variant: 'login'
}
}
],
afterNavLinks: [
...config.admin?.components?.afterNavLinks ?? [],
{
path: '@intecion/ipal-kit/admin#IntecionCredit',
serverProps: creditProps
serverProps: {
...creditProps,
variant: 'nav'
}
}
]
} : {}
+1 -1
View File
File diff suppressed because one or more lines are too long
+24 -1
View File
@@ -1,4 +1,15 @@
import type { Field } from 'payload';
import type { Field, Plugin } from 'payload';
/**
* Factory shape of @clocklimited/payload-2fa's `payloadTotp` export — injected
* so the plugin never imports the optional peer itself.
*/
export type TotpPluginFactory = (options: {
collection: string;
forceSetup: boolean;
totp: {
issuer: string;
};
}) => Plugin;
import type { AccessOption } from './modules/access/types.js';
import type { ContentOption } from './modules/content/types.js';
import type { FormsOption } from './modules/forms/types.js';
@@ -71,6 +82,18 @@ export type IpalOptions = {
collectionSlug?: string;
/** 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.
*/
plugin?: TotpPluginFactory;
} | false;
/**
* White-label the admin panel: show the CLIENT's brand (logo + name) in the
+1 -1
View File
File diff suppressed because one or more lines are too long