@delmaredigital/payload-better-auth 0.3.5 → 0.3.6

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"betterAuthDefaults.d.ts","sourceRoot":"","sources":["../../src/utils/betterAuthDefaults.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAEhE,KAAK,mBAAmB,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAA;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAkE2mE,CAAC;;;;;;;;;;;;;;4BAA4Z,CAAC;mCAAgD,CAAC;;;;2DAA0P,CAAC;;;;4CAA+H,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;6EAAi5C,CAAC;;;;;;;;;;;;;4BAA0d,CAAC;;;;;;;;;;;;;;;;;;;mCAAgzB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAA84Q,CAAC;iCAAkD,CAAC;;;;;;;;;6BAA8Q,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAAkyX,CAAC;iCAAkD,CAAC;;;;;;;;;6BAA8Q,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAAi5D,CAAC;iCAAkD,CAAC;;;;;;;;;6BAA8Q,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA7D5p5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,iBAAiB,EAChE,OAAO,EAAE,CAAC,GACT,CAAC,CAgBH"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Utility to apply sensible defaults to Better Auth options.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ import { apiKey as betterAuthApiKey } from 'better-auth/plugins';
7
+ /**
8
+ * API Key plugin with sensible defaults for use with this package.
9
+ *
10
+ * Enables metadata storage by default so that scopes can be displayed
11
+ * in the admin UI after key creation.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { apiKeyWithDefaults } from '@delmaredigital/payload-better-auth'
16
+ *
17
+ * export const betterAuthOptions = {
18
+ * plugins: [
19
+ * apiKeyWithDefaults(), // metadata enabled by default
20
+ * ],
21
+ * }
22
+ * ```
23
+ *
24
+ * @example With custom options
25
+ * ```ts
26
+ * apiKeyWithDefaults({
27
+ * rateLimit: { max: 100, window: 60 },
28
+ * // enableMetadata is already true
29
+ * })
30
+ * ```
31
+ */
32
+ export function apiKeyWithDefaults(options) {
33
+ return betterAuthApiKey({
34
+ enableMetadata: true,
35
+ ...options,
36
+ });
37
+ }
38
+ /**
39
+ * Applies sensible defaults to Better Auth options.
40
+ *
41
+ * Currently applies the following defaults:
42
+ * - `trustedOrigins`: If not explicitly provided but `baseURL` is set,
43
+ * defaults to `[baseURL]`. This handles the common single-domain case
44
+ * where the app's origin should be trusted for auth requests.
45
+ *
46
+ * Multi-domain setups can still explicitly set `trustedOrigins` to include
47
+ * multiple origins.
48
+ *
49
+ * @example Simple case - trustedOrigins defaults to [baseURL]
50
+ * ```ts
51
+ * import { withBetterAuthDefaults } from '@delmaredigital/payload-better-auth'
52
+ *
53
+ * const auth = betterAuth(withBetterAuthDefaults({
54
+ * baseURL: 'https://myapp.com',
55
+ * // trustedOrigins automatically becomes ['https://myapp.com']
56
+ * }))
57
+ * ```
58
+ *
59
+ * @example Multi-domain case - explicit trustedOrigins respected
60
+ * ```ts
61
+ * const auth = betterAuth(withBetterAuthDefaults({
62
+ * baseURL: 'https://myapp.com',
63
+ * trustedOrigins: ['https://myapp.com', 'https://other-domain.com'],
64
+ * // trustedOrigins stays as explicitly provided
65
+ * }))
66
+ * ```
67
+ *
68
+ * @example With createBetterAuthPlugin
69
+ * ```ts
70
+ * createBetterAuthPlugin({
71
+ * createAuth: (payload) => betterAuth(withBetterAuthDefaults({
72
+ * database: payloadAdapter({ payloadClient: payload }),
73
+ * baseURL: process.env.BETTER_AUTH_URL,
74
+ * })),
75
+ * })
76
+ * ```
77
+ */
78
+ export function withBetterAuthDefaults(options) {
79
+ // If trustedOrigins is explicitly provided, use it as-is
80
+ if (options.trustedOrigins !== undefined) {
81
+ return options;
82
+ }
83
+ // If baseURL is set, default trustedOrigins to [baseURL]
84
+ if (options.baseURL) {
85
+ return {
86
+ ...options,
87
+ trustedOrigins: [options.baseURL],
88
+ };
89
+ }
90
+ // No defaults to apply
91
+ return options;
92
+ }
93
+ //# sourceMappingURL=betterAuthDefaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"betterAuthDefaults.js","sourceRoot":"","sources":["../../src/utils/betterAuthDefaults.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAIhE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAA6B;IAC9D,OAAO,gBAAgB,CAAC;QACtB,cAAc,EAAE,IAAI;QACpB,GAAG,OAAO;KACX,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,UAAU,sBAAsB,CACpC,OAAU;IAEV,yDAAyD;IACzD,IAAI,OAAO,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;QACzC,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,yDAAyD;IACzD,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO;YACL,GAAG,OAAO;YACV,cAAc,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;SAClC,CAAA;IACH,CAAC;IAED,uBAAuB;IACvB,OAAO,OAAO,CAAA;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delmaredigital/payload-better-auth",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "Better Auth adapter and plugins for Payload CMS",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -54,7 +54,7 @@
54
54
  "scripts": {
55
55
  "build": "tsc",
56
56
  "dev": "tsc --watch",
57
- "dev-publish": "pnpm build && pnpm version prerelease --preid=dev && pnpm publish --registry http://localhost:4873",
57
+ "dev-publish": "pnpm build && pnpm version prerelease --preid=dev --no-git-tag-version && pnpm publish --registry http://localhost:4873 --no-git-checks",
58
58
  "clean": "rm -rf dist",
59
59
  "generate:types": "tsx src/scripts/generate-types.ts",
60
60
  "test": "vitest run",
@@ -82,7 +82,7 @@
82
82
  "better-auth": "^1.4.17",
83
83
  "next": "^16.1.4",
84
84
  "payload": "^3.73.0",
85
- "react": "^19.2.3",
85
+ "react": "^19.2.4",
86
86
  "tsx": "^4.21.0",
87
87
  "typescript": "^5.9.3",
88
88
  "vitest": "^2.1.9"