@opensaas/stack-auth 0.39.2 → 0.40.0

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.
Files changed (104) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +151 -0
  3. package/CLAUDE.md +140 -22
  4. package/dist/client/index.d.ts +0 -16
  5. package/dist/client/index.d.ts.map +1 -1
  6. package/dist/config/adopt-better-auth-tables.d.ts +4 -49
  7. package/dist/config/adopt-better-auth-tables.d.ts.map +1 -1
  8. package/dist/config/adopt-better-auth-tables.js +4 -51
  9. package/dist/config/adopt-better-auth-tables.js.map +1 -1
  10. package/dist/config/derive-auth-lists.d.ts +42 -37
  11. package/dist/config/derive-auth-lists.d.ts.map +1 -1
  12. package/dist/config/derive-auth-lists.js +579 -223
  13. package/dist/config/derive-auth-lists.js.map +1 -1
  14. package/dist/config/index.d.ts +0 -3
  15. package/dist/config/index.d.ts.map +1 -1
  16. package/dist/config/index.js +4 -34
  17. package/dist/config/index.js.map +1 -1
  18. package/dist/config/plugin.d.ts.map +1 -1
  19. package/dist/config/plugin.js +20 -90
  20. package/dist/config/plugin.js.map +1 -1
  21. package/dist/config/types.d.ts +89 -67
  22. package/dist/config/types.d.ts.map +1 -1
  23. package/dist/index.d.ts +1 -9
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +3 -13
  26. package/dist/index.js.map +1 -1
  27. package/dist/lists/index.d.ts +9 -5
  28. package/dist/lists/index.d.ts.map +1 -1
  29. package/dist/lists/index.js +9 -6
  30. package/dist/lists/index.js.map +1 -1
  31. package/dist/mcp/better-auth.d.ts +6 -19
  32. package/dist/mcp/better-auth.d.ts.map +1 -1
  33. package/dist/mcp/better-auth.js +6 -20
  34. package/dist/mcp/better-auth.js.map +1 -1
  35. package/dist/plugins/index.d.ts +4 -4
  36. package/dist/plugins/index.d.ts.map +1 -1
  37. package/dist/plugins/index.js +4 -4
  38. package/dist/plugins/index.js.map +1 -1
  39. package/dist/runtime/types.d.ts +2 -9
  40. package/dist/runtime/types.d.ts.map +1 -1
  41. package/dist/runtime/types.js +0 -4
  42. package/dist/runtime/types.js.map +1 -1
  43. package/dist/server/index.d.ts +5 -12
  44. package/dist/server/index.d.ts.map +1 -1
  45. package/dist/server/index.js +14 -62
  46. package/dist/server/index.js.map +1 -1
  47. package/dist/ui/components/ForgotPasswordForm.d.ts +0 -3
  48. package/dist/ui/components/ForgotPasswordForm.d.ts.map +1 -1
  49. package/dist/ui/components/ForgotPasswordForm.js +0 -3
  50. package/dist/ui/components/ForgotPasswordForm.js.map +1 -1
  51. package/dist/ui/components/ResetPasswordForm.d.ts +0 -3
  52. package/dist/ui/components/ResetPasswordForm.d.ts.map +1 -1
  53. package/dist/ui/components/ResetPasswordForm.js +0 -5
  54. package/dist/ui/components/ResetPasswordForm.js.map +1 -1
  55. package/dist/ui/components/SignInForm.d.ts +0 -3
  56. package/dist/ui/components/SignInForm.d.ts.map +1 -1
  57. package/dist/ui/components/SignInForm.js +0 -4
  58. package/dist/ui/components/SignInForm.js.map +1 -1
  59. package/dist/ui/components/SignUpForm.d.ts +0 -3
  60. package/dist/ui/components/SignUpForm.d.ts.map +1 -1
  61. package/dist/ui/components/SignUpForm.js +0 -5
  62. package/dist/ui/components/SignUpForm.js.map +1 -1
  63. package/dist/ui/lib/clean-error-message.d.ts +3 -6
  64. package/dist/ui/lib/clean-error-message.d.ts.map +1 -1
  65. package/dist/ui/lib/clean-error-message.js +3 -6
  66. package/dist/ui/lib/clean-error-message.js.map +1 -1
  67. package/dist/ui/types.d.ts +2 -15
  68. package/dist/ui/types.d.ts.map +1 -1
  69. package/dist/ui/types.js +2 -7
  70. package/dist/ui/types.js.map +1 -1
  71. package/package.json +12 -5
  72. package/src/client/index.ts +0 -17
  73. package/src/config/adopt-better-auth-tables.ts +4 -51
  74. package/src/config/derive-auth-lists.ts +685 -252
  75. package/src/config/index.ts +4 -34
  76. package/src/config/plugin.ts +21 -91
  77. package/src/config/types.ts +90 -67
  78. package/src/index.ts +3 -14
  79. package/src/lists/index.ts +17 -5
  80. package/src/mcp/better-auth.ts +6 -25
  81. package/src/plugins/index.ts +4 -5
  82. package/src/runtime/types.ts +2 -10
  83. package/src/server/index.ts +17 -70
  84. package/src/ui/components/ForgotPasswordForm.tsx +0 -3
  85. package/src/ui/components/ResetPasswordForm.tsx +0 -5
  86. package/src/ui/components/SignInForm.tsx +0 -4
  87. package/src/ui/components/SignUpForm.tsx +0 -5
  88. package/src/ui/lib/clean-error-message.ts +3 -6
  89. package/src/ui/types.ts +2 -15
  90. package/tests/auth-lists-drift.test.ts +480 -0
  91. package/tests/config.test.ts +3 -0
  92. package/tests/credential-field-read-deny-e2e.test.ts +295 -0
  93. package/tests/derive-auth-lists.test.ts +263 -6
  94. package/tests/generated-fk-shape.test.ts +432 -9
  95. package/tests/mcp-oauth-cascade-e2e.test.ts +267 -0
  96. package/tests/plugin-derived-keys.test.ts +39 -0
  97. package/tests/plugin-table-derivation.test.ts +270 -0
  98. package/tsconfig.tsbuildinfo +1 -1
  99. package/dist/server/schema-converter.d.ts +0 -81
  100. package/dist/server/schema-converter.d.ts.map +0 -1
  101. package/dist/server/schema-converter.js +0 -157
  102. package/dist/server/schema-converter.js.map +0 -1
  103. package/src/server/schema-converter.ts +0 -243
  104. package/tests/schema-converter.test.ts +0 -399
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opensaas/stack-auth",
3
- "version": "0.39.2",
3
+ "version": "0.40.0",
4
4
  "description": "Better-auth integration for OpenSaas Stack",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -49,24 +49,31 @@
49
49
  "url": "https://github.com/OpenSaasAU/stack/issues"
50
50
  },
51
51
  "peerDependencies": {
52
+ "@better-auth/mcp": "^1.7.0",
52
53
  "@opensaas/stack-core": "^0",
53
- "better-auth": "^1.3.29",
54
+ "better-auth": "^1.4.0",
54
55
  "next": "^15.0.0 || ^16.0.0",
55
56
  "react": "^18.0.0 || ^19.0.0"
56
57
  },
58
+ "peerDependenciesMeta": {
59
+ "@better-auth/mcp": {
60
+ "optional": true
61
+ }
62
+ },
57
63
  "devDependencies": {
64
+ "@better-auth/mcp": "^1.7.1",
58
65
  "@types/node": "^26.1.1",
59
66
  "@types/react": "^19.2.14",
60
67
  "@typescript/native": "npm:typescript@^7.0.2",
61
68
  "@vitest/coverage-v8": "^4.1.10",
62
69
  "@vitest/ui": "^4.1.10",
63
- "better-auth": "^1.6.25",
70
+ "better-auth": "^1.7.1",
64
71
  "next": "^16.2.10",
65
72
  "react": "^19.2.8",
66
73
  "typescript": "npm:@typescript/typescript6@^6.0.2",
67
74
  "vitest": "^4.1.10",
68
- "@opensaas/stack-cli": "0.39.2",
69
- "@opensaas/stack-core": "0.39.2"
75
+ "@opensaas/stack-cli": "0.40.0",
76
+ "@opensaas/stack-core": "0.40.0"
70
77
  },
71
78
  "scripts": {
72
79
  "build": "tsc",
@@ -24,21 +24,4 @@ export function createClient(options: { baseURL: string }): ReturnType<typeof cr
24
24
  })
25
25
  }
26
26
 
27
- /**
28
- * Re-export useful types from better-auth
29
- */
30
27
  export type { Session }
31
-
32
- /**
33
- * Note: React hooks (useSession, etc.) are accessed from the client instance
34
- *
35
- * @example
36
- * ```typescript
37
- * import { authClient } from '@/lib/auth-client'
38
- *
39
- * function MyComponent() {
40
- * const { data: session } = authClient.useSession()
41
- * // ...
42
- * }
43
- * ```
44
- */
@@ -1,49 +1,8 @@
1
1
  /**
2
- * "Adopt existing better-auth tables" recipe.
3
- *
4
- * A migrating project usually already has a working, hand-wired better-auth
5
- * installation: its tables are `AuthUser`/`AuthSession`/`AuthAccount`/
6
- * `AuthVerification`, mapped into a separate `auth` Postgres schema, and its
7
- * application `User` (`public.User`) is a *different* model. Reconstructing the
8
- * matching {@link AuthConfig} by hand — four `modelName`s plus a `schema` on each
9
- * model — is repetitive and easy to get wrong.
10
- *
11
- * {@link adoptBetterAuthTables} produces that {@link AuthConfig} fragment from a
12
- * couple of options so the migrator doesn't rebuild it from scratch. It only
13
- * sets the *adoption* knobs (per-model `modelName` + the plugin-level `schema`);
14
- * the developer composes it with the rest of their auth config (providers,
15
- * session fields, `extendUserList`, etc.):
16
- *
17
- * ```typescript
18
- * authPlugin({
19
- * ...adoptBetterAuthTables(),
20
- * emailAndPassword: { enabled: true },
21
- * sessionFields: ['userId', 'email', 'name'],
22
- * })
23
- * ```
24
- *
25
- * Combined with the keys/field derivation (`deriveAuthLists`) and schema
26
- * placement, the generated Auth lists reach **Schema parity** with the live
27
- * tables — they are modelled for runtime/types without producing a destructive
28
- * auth migration. The recipe never touches the application's own domain `User`:
29
- * its model names are `Auth`-prefixed by default and the plugin only ever
30
- * adds/extends its *derived* keys.
31
- *
32
- * The single most common adoption shape is a project that ran better-auth
33
- * *before* adding Stack: its live tables are still better-auth's own default
34
- * lowercase names (`user`/`session`/`account`/`verification`), even though the
35
- * derived list keys need the `Auth` prefix to avoid colliding with the app's
36
- * own domain `User`. Pass `useBetterAuthTableNames: true` to point every
37
- * model's physical table at that default while keeping the prefixed list keys
38
- * (or `tableNames` for an explicit per-model override):
39
- *
40
- * ```typescript
41
- * authPlugin({
42
- * ...adoptBetterAuthTables({ useBetterAuthTableNames: true }),
43
- * // AuthUser/AuthSession/AuthAccount/AuthVerification list keys,
44
- * // @@map("user")/@@map("session")/@@map("account")/@@map("verification")
45
- * })
46
- * ```
2
+ * "Adopt existing better-auth tables" recipe: produces the {@link AuthConfig}
3
+ * adoption fragment for a pre-existing better-auth install. See
4
+ * `packages/auth/CLAUDE.md` ("Adopting an existing better-auth install") for
5
+ * the full rationale and examples.
47
6
  */
48
7
 
49
8
  import type { AuthConfig, AuthModelConfig } from './types.js'
@@ -157,7 +116,6 @@ export type AdoptBetterAuthTablesOptions = {
157
116
  rateLimit?: boolean
158
117
  }
159
118
 
160
- /** The better-auth models and their default (unprefixed) model names. */
161
119
  const MODEL_DEFAULT_NAMES = {
162
120
  user: 'User',
163
121
  session: 'Session',
@@ -166,7 +124,6 @@ const MODEL_DEFAULT_NAMES = {
166
124
  rateLimit: 'RateLimit',
167
125
  } as const
168
126
 
169
- /** better-auth's own default lowercase table names, per model. */
170
127
  const BETTER_AUTH_DEFAULT_TABLE_NAMES = {
171
128
  user: 'user',
172
129
  session: 'session',
@@ -195,10 +152,6 @@ export type AdoptBetterAuthTablesConfig = Pick<
195
152
  *
196
153
  * Returns only the model/schema knobs needed to adopt the live tables; spread it
197
154
  * into {@link authPlugin} alongside your own auth config.
198
- *
199
- * @param options - Adoption conventions (schema, model-name prefix, column maps)
200
- * @returns An {@link AuthConfig} fragment with `schema` + per-model `modelName`
201
- * (and any field column maps) set to match the live tables
202
155
  */
203
156
  export function adoptBetterAuthTables(
204
157
  options: AdoptBetterAuthTablesOptions = {},