@opensaas/stack-auth 0.39.2 → 0.41.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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +153 -0
- package/CLAUDE.md +140 -22
- package/dist/client/index.d.ts +0 -16
- package/dist/client/index.d.ts.map +1 -1
- package/dist/config/adopt-better-auth-tables.d.ts +4 -49
- package/dist/config/adopt-better-auth-tables.d.ts.map +1 -1
- package/dist/config/adopt-better-auth-tables.js +4 -51
- package/dist/config/adopt-better-auth-tables.js.map +1 -1
- package/dist/config/derive-auth-lists.d.ts +42 -37
- package/dist/config/derive-auth-lists.d.ts.map +1 -1
- package/dist/config/derive-auth-lists.js +579 -223
- package/dist/config/derive-auth-lists.js.map +1 -1
- package/dist/config/index.d.ts +0 -3
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +4 -34
- package/dist/config/index.js.map +1 -1
- package/dist/config/plugin.d.ts.map +1 -1
- package/dist/config/plugin.js +20 -90
- package/dist/config/plugin.js.map +1 -1
- package/dist/config/types.d.ts +89 -67
- package/dist/config/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -13
- package/dist/index.js.map +1 -1
- package/dist/lists/index.d.ts +9 -5
- package/dist/lists/index.d.ts.map +1 -1
- package/dist/lists/index.js +9 -6
- package/dist/lists/index.js.map +1 -1
- package/dist/mcp/better-auth.d.ts +6 -19
- package/dist/mcp/better-auth.d.ts.map +1 -1
- package/dist/mcp/better-auth.js +6 -20
- package/dist/mcp/better-auth.js.map +1 -1
- package/dist/plugins/index.d.ts +4 -4
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +4 -4
- package/dist/plugins/index.js.map +1 -1
- package/dist/runtime/types.d.ts +2 -9
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/types.js +0 -4
- package/dist/runtime/types.js.map +1 -1
- package/dist/server/index.d.ts +5 -12
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +14 -62
- package/dist/server/index.js.map +1 -1
- package/dist/ui/components/ForgotPasswordForm.d.ts +0 -3
- package/dist/ui/components/ForgotPasswordForm.d.ts.map +1 -1
- package/dist/ui/components/ForgotPasswordForm.js +0 -3
- package/dist/ui/components/ForgotPasswordForm.js.map +1 -1
- package/dist/ui/components/ResetPasswordForm.d.ts +0 -3
- package/dist/ui/components/ResetPasswordForm.d.ts.map +1 -1
- package/dist/ui/components/ResetPasswordForm.js +0 -5
- package/dist/ui/components/ResetPasswordForm.js.map +1 -1
- package/dist/ui/components/SignInForm.d.ts +0 -3
- package/dist/ui/components/SignInForm.d.ts.map +1 -1
- package/dist/ui/components/SignInForm.js +0 -4
- package/dist/ui/components/SignInForm.js.map +1 -1
- package/dist/ui/components/SignUpForm.d.ts +0 -3
- package/dist/ui/components/SignUpForm.d.ts.map +1 -1
- package/dist/ui/components/SignUpForm.js +0 -5
- package/dist/ui/components/SignUpForm.js.map +1 -1
- package/dist/ui/lib/clean-error-message.d.ts +3 -6
- package/dist/ui/lib/clean-error-message.d.ts.map +1 -1
- package/dist/ui/lib/clean-error-message.js +3 -6
- package/dist/ui/lib/clean-error-message.js.map +1 -1
- package/dist/ui/types.d.ts +2 -15
- package/dist/ui/types.d.ts.map +1 -1
- package/dist/ui/types.js +2 -7
- package/dist/ui/types.js.map +1 -1
- package/package.json +12 -5
- package/src/client/index.ts +0 -17
- package/src/config/adopt-better-auth-tables.ts +4 -51
- package/src/config/derive-auth-lists.ts +685 -252
- package/src/config/index.ts +4 -34
- package/src/config/plugin.ts +21 -91
- package/src/config/types.ts +90 -67
- package/src/index.ts +3 -14
- package/src/lists/index.ts +17 -5
- package/src/mcp/better-auth.ts +6 -25
- package/src/plugins/index.ts +4 -5
- package/src/runtime/types.ts +2 -10
- package/src/server/index.ts +17 -70
- package/src/ui/components/ForgotPasswordForm.tsx +0 -3
- package/src/ui/components/ResetPasswordForm.tsx +0 -5
- package/src/ui/components/SignInForm.tsx +0 -4
- package/src/ui/components/SignUpForm.tsx +0 -5
- package/src/ui/lib/clean-error-message.ts +3 -6
- package/src/ui/types.ts +2 -15
- package/tests/auth-lists-drift.test.ts +480 -0
- package/tests/config.test.ts +3 -0
- package/tests/credential-field-read-deny-e2e.test.ts +295 -0
- package/tests/derive-auth-lists.test.ts +263 -6
- package/tests/generated-fk-shape.test.ts +432 -9
- package/tests/mcp-oauth-cascade-e2e.test.ts +267 -0
- package/tests/plugin-derived-keys.test.ts +39 -0
- package/tests/plugin-table-derivation.test.ts +270 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/server/schema-converter.d.ts +0 -81
- package/dist/server/schema-converter.d.ts.map +0 -1
- package/dist/server/schema-converter.js +0 -157
- package/dist/server/schema-converter.js.map +0 -1
- package/src/server/schema-converter.ts +0 -243
- 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.
|
|
3
|
+
"version": "0.41.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.
|
|
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.
|
|
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.
|
|
69
|
-
"@opensaas/stack-core": "0.
|
|
75
|
+
"@opensaas/stack-cli": "0.41.0",
|
|
76
|
+
"@opensaas/stack-core": "0.41.0"
|
|
70
77
|
},
|
|
71
78
|
"scripts": {
|
|
72
79
|
"build": "tsc",
|
package/src/client/index.ts
CHANGED
|
@@ -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
|
-
*
|
|
5
|
-
*
|
|
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 = {},
|