@delmaredigital/payload-better-auth 0.4.1 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @packageDocumentation
8
8
  */ // Adapter
9
- export { payloadAdapter } from './adapter/index.js';
9
+ export { payloadAdapter, detectDbType, resolveIdType } from './adapter/index.js';
10
10
  // Collection generator plugin
11
11
  export { betterAuthCollections } from './adapter/collections.js';
12
12
  // Payload plugin and strategy
@@ -314,6 +314,9 @@ let apiKeyScopesConfig = undefined;
314
314
  }
315
315
  /**
316
316
  * Injects management UI components into the Payload config based on enabled plugins.
317
+ *
318
+ * - 2FA and Passkeys are injected as `ui` fields on the auth collection (per-user settings)
319
+ * - API Keys remain as a sidebar admin view (admin-level feature)
317
320
  */ function injectManagementComponents(config, options) {
318
321
  const adminOptions = options.admin ?? {};
319
322
  // Skip if management UI is disabled
@@ -324,55 +327,72 @@ let apiKeyScopesConfig = undefined;
324
327
  const enabledPlugins = detectEnabledPlugins(adminOptions.betterAuthOptions);
325
328
  // Get custom paths or use defaults
326
329
  const paths = {
327
- twoFactor: adminOptions.managementPaths?.twoFactor ?? '/security/two-factor',
328
- apiKeys: adminOptions.managementPaths?.apiKeys ?? '/security/api-keys',
329
- passkeys: adminOptions.managementPaths?.passkeys ?? '/security/passkeys'
330
+ apiKeys: adminOptions.managementPaths?.apiKeys ?? '/security/api-keys'
330
331
  };
331
332
  const existingComponents = config.admin?.components ?? {};
332
333
  const existingViews = existingComponents.views ?? {};
333
334
  const existingAfterNavLinks = existingComponents.afterNavLinks ?? [];
334
- // Build management views based on enabled plugins
335
- // Note: Sessions and passkeys use Payload's default collection views
335
+ // Build management views only API Keys stays as a sidebar view
336
336
  const managementViews = {};
337
- // Two-factor (if enabled)
338
- if (enabledPlugins.hasTwoFactor) {
339
- managementViews.securityTwoFactor = {
340
- Component: '@delmaredigital/payload-better-auth/rsc#TwoFactorView',
341
- path: paths.twoFactor
342
- };
343
- }
344
- // API keys (if enabled)
345
337
  if (enabledPlugins.hasApiKey) {
346
338
  managementViews.securityApiKeys = {
347
339
  Component: '@delmaredigital/payload-better-auth/rsc#ApiKeysView',
348
340
  path: paths.apiKeys
349
341
  };
350
342
  }
351
- // Passkeys (if enabled)
352
- if (enabledPlugins.hasPasskey) {
353
- managementViews.securityPasskeys = {
354
- Component: '@delmaredigital/payload-better-auth/rsc#PasskeysView',
355
- path: paths.passkeys
356
- };
357
- }
358
- // Only add nav links if at least one plugin is enabled
359
- const hasAnyPlugin = enabledPlugins.hasTwoFactor || enabledPlugins.hasApiKey || enabledPlugins.hasPasskey;
360
- // Add SecurityNavLinks to afterNavLinks with clientProps for enabled plugins
361
- const afterNavLinks = hasAnyPlugin ? [
343
+ // Only add nav links if API Keys is enabled
344
+ const afterNavLinks = enabledPlugins.hasApiKey ? [
362
345
  ...Array.isArray(existingAfterNavLinks) ? existingAfterNavLinks : [
363
346
  existingAfterNavLinks
364
347
  ],
365
348
  {
366
349
  path: '@delmaredigital/payload-better-auth/components/management#SecurityNavLinks',
367
350
  clientProps: {
368
- showTwoFactor: enabledPlugins.hasTwoFactor,
369
- showApiKeys: enabledPlugins.hasApiKey,
370
- showPasskeys: enabledPlugins.hasPasskey
351
+ showApiKeys: enabledPlugins.hasApiKey
371
352
  }
372
353
  }
373
354
  ] : existingAfterNavLinks;
355
+ // Inject 2FA and Passkeys as ui fields on the auth collection
356
+ const securityFields = [];
357
+ if (enabledPlugins.hasTwoFactor) {
358
+ securityFields.push({
359
+ type: 'ui',
360
+ name: 'twoFactorManagement',
361
+ label: 'Two-Factor Authentication',
362
+ admin: {
363
+ components: {
364
+ Field: '@delmaredigital/payload-better-auth/components#TwoFactorField'
365
+ }
366
+ }
367
+ });
368
+ }
369
+ if (enabledPlugins.hasPasskey) {
370
+ securityFields.push({
371
+ type: 'ui',
372
+ name: 'passkeysManagement',
373
+ label: 'Passkeys',
374
+ admin: {
375
+ components: {
376
+ Field: '@delmaredigital/payload-better-auth/components#PasskeysField'
377
+ }
378
+ }
379
+ });
380
+ }
381
+ // Add ui fields to the auth collection
382
+ const collections = (config.collections ?? []).map((collection)=>{
383
+ const isAuthCollection = collection.auth === true || typeof collection.auth === 'object' && collection.auth.disableLocalStrategy;
384
+ if (!isAuthCollection || securityFields.length === 0) return collection;
385
+ return {
386
+ ...collection,
387
+ fields: [
388
+ ...collection.fields ?? [],
389
+ ...securityFields
390
+ ]
391
+ };
392
+ });
374
393
  return {
375
394
  ...config,
395
+ collections,
376
396
  admin: {
377
397
  ...config.admin,
378
398
  components: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delmaredigital/payload-better-auth",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "Better Auth adapter and plugins for Payload CMS",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -89,17 +89,17 @@
89
89
  }
90
90
  },
91
91
  "devDependencies": {
92
- "@payloadcms/next": "^3.76.1",
93
- "@payloadcms/ui": "^3.76.1",
92
+ "@better-auth/passkey": "^1.4.18",
93
+ "@payloadcms/next": "^3.77.0",
94
+ "@payloadcms/ui": "^3.77.0",
94
95
  "@swc/cli": "^0.6.0",
95
96
  "@swc/core": "^1.15.11",
96
- "@types/node": "^25.2.3",
97
+ "@types/node": "^25.3.0",
97
98
  "@types/react": "^19.2.14",
98
99
  "@vitest/coverage-v8": "^2.1.9",
99
- "@better-auth/passkey": "^1.4.18",
100
100
  "better-auth": "^1.4.18",
101
101
  "next": "^16.1.6",
102
- "payload": "^3.76.1",
102
+ "payload": "^3.77.0",
103
103
  "react": "^19.2.4",
104
104
  "tsx": "^4.21.0",
105
105
  "typescript": "^5.9.3",