2FA fixed
This commit is contained in:
Vendored
+6
-5
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user