@proofkit/better-auth 0.4.0-beta.7 → 0.4.0-beta.9
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/bin/intent.js +20 -0
- package/package.json +11 -5
- package/skills/better-auth-setup/SKILL.md +233 -0
package/bin/intent.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Auto-generated by @tanstack/intent setup
|
|
3
|
+
// Exposes the intent end-user CLI for consumers of this library.
|
|
4
|
+
// Commit this file, then add to your package.json:
|
|
5
|
+
// "bin": { "intent": "./bin/intent.js" }
|
|
6
|
+
try {
|
|
7
|
+
await import('@tanstack/intent/intent-library')
|
|
8
|
+
} catch (e) {
|
|
9
|
+
if (e?.code === 'ERR_MODULE_NOT_FOUND' || e?.code === 'MODULE_NOT_FOUND') {
|
|
10
|
+
console.error('@tanstack/intent is not installed.')
|
|
11
|
+
console.error('')
|
|
12
|
+
console.error('Install it as a dev dependency:')
|
|
13
|
+
console.error(' npm add -D @tanstack/intent')
|
|
14
|
+
console.error('')
|
|
15
|
+
console.error('Or run directly:')
|
|
16
|
+
console.error(' npx @tanstack/intent@latest list')
|
|
17
|
+
process.exit(1)
|
|
18
|
+
}
|
|
19
|
+
throw e
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proofkit/better-auth",
|
|
3
|
-
"version": "0.4.0-beta.
|
|
3
|
+
"version": "0.4.0-beta.9",
|
|
4
4
|
"description": "FileMaker adapter for Better Auth",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/esm/index.js",
|
|
7
7
|
"bin": {
|
|
8
|
-
"better-auth": "./dist/esm/cli/index.js"
|
|
8
|
+
"better-auth": "./dist/esm/cli/index.js",
|
|
9
|
+
"intent": "./bin/intent.js"
|
|
9
10
|
},
|
|
10
11
|
"exports": {
|
|
11
12
|
".": {
|
|
@@ -22,11 +23,15 @@
|
|
|
22
23
|
"fmdapi",
|
|
23
24
|
"proofgeist",
|
|
24
25
|
"filemaker",
|
|
25
|
-
"fmrest"
|
|
26
|
+
"fmrest",
|
|
27
|
+
"tanstack-intent"
|
|
26
28
|
],
|
|
27
29
|
"files": [
|
|
28
30
|
"dist",
|
|
29
|
-
"src"
|
|
31
|
+
"src",
|
|
32
|
+
"skills",
|
|
33
|
+
"bin",
|
|
34
|
+
"!skills/_artifacts"
|
|
30
35
|
],
|
|
31
36
|
"author": "",
|
|
32
37
|
"license": "ISC",
|
|
@@ -48,9 +53,10 @@
|
|
|
48
53
|
"fs-extra": "^11.3.3",
|
|
49
54
|
"prompts": "^2.4.2",
|
|
50
55
|
"vite": "^6.4.1",
|
|
51
|
-
"@proofkit/fmodata": "0.1.0-beta.
|
|
56
|
+
"@proofkit/fmodata": "0.1.0-beta.33"
|
|
52
57
|
},
|
|
53
58
|
"devDependencies": {
|
|
59
|
+
"@tanstack/intent": "^0.0.19",
|
|
54
60
|
"@types/fs-extra": "^11.0.4",
|
|
55
61
|
"@types/prompts": "^2.4.9",
|
|
56
62
|
"@vitest/ui": "^3.2.4",
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: better-auth-setup
|
|
3
|
+
description: >
|
|
4
|
+
Set up self-hosted authentication with better-auth using FileMaker as the
|
|
5
|
+
database backend. Covers FileMakerAdapter, FMServerConnection, betterAuth
|
|
6
|
+
config, migration via npx @proofkit/better-auth migrate, OData prerequisites,
|
|
7
|
+
fmodata privilege, Full Access credentials for schema modification, plugin
|
|
8
|
+
migration workflow, troubleshooting "filemaker is not supported" errors.
|
|
9
|
+
type: core
|
|
10
|
+
library: proofkit
|
|
11
|
+
library_version: "0.4.0-beta.7"
|
|
12
|
+
requires:
|
|
13
|
+
- fmodata-client
|
|
14
|
+
sources:
|
|
15
|
+
- "proofgeist/proofkit:packages/better-auth/src/*.ts"
|
|
16
|
+
- "proofgeist/proofkit:apps/docs/content/docs/better-auth/*.mdx"
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Setup
|
|
20
|
+
|
|
21
|
+
### Prerequisites
|
|
22
|
+
|
|
23
|
+
- OData enabled on FileMaker Server
|
|
24
|
+
- API credentials with `fmodata` privilege enabled
|
|
25
|
+
- Read/write access to the better-auth tables
|
|
26
|
+
- Full Access credentials available for schema migration (can differ from runtime credentials)
|
|
27
|
+
|
|
28
|
+
### Install packages
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pnpm add @proofkit/better-auth @proofkit/fmodata
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Configure auth.ts
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { betterAuth } from "better-auth";
|
|
38
|
+
import { FMServerConnection } from "@proofkit/fmodata";
|
|
39
|
+
import { FileMakerAdapter } from "@proofkit/better-auth";
|
|
40
|
+
|
|
41
|
+
const connection = new FMServerConnection({
|
|
42
|
+
serverUrl: process.env.FM_SERVER_URL!,
|
|
43
|
+
auth: {
|
|
44
|
+
username: process.env.FM_USERNAME!,
|
|
45
|
+
password: process.env.FM_PASSWORD!,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const db = connection.database(process.env.FM_DATABASE!);
|
|
50
|
+
|
|
51
|
+
export const auth = betterAuth({
|
|
52
|
+
database: FileMakerAdapter({ database: db }),
|
|
53
|
+
// add plugins, social providers, etc.
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`FileMakerAdapter` accepts a `FileMakerAdapterConfig`:
|
|
58
|
+
|
|
59
|
+
- `database` (required) -- an fmodata `Database` instance
|
|
60
|
+
- `debugLogs` (optional) -- enable adapter debug logging
|
|
61
|
+
- `usePlural` (optional) -- set `true` if table names are plural
|
|
62
|
+
|
|
63
|
+
The adapter maps Better Auth operations (create, findOne, findMany, update, delete, count) to OData requests via `db._makeRequest`. It does not support JSON columns, native dates, or native booleans -- all values are stored as strings/numbers.
|
|
64
|
+
|
|
65
|
+
### Alternative: Data API key (OttoFMS 4.11+)
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
const connection = new FMServerConnection({
|
|
69
|
+
serverUrl: process.env.FM_SERVER_URL!,
|
|
70
|
+
auth: {
|
|
71
|
+
apiKey: process.env.OTTO_API_KEY!,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
OData must be enabled for the key.
|
|
77
|
+
|
|
78
|
+
## Core Patterns
|
|
79
|
+
|
|
80
|
+
### 1. Initial migration
|
|
81
|
+
|
|
82
|
+
After configuring `auth.ts`, run the migration CLI to create tables and fields in FileMaker:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npx @proofkit/better-auth migrate
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The CLI:
|
|
89
|
+
|
|
90
|
+
1. Loads your `auth.ts` config (auto-detected or via `--config <path>`)
|
|
91
|
+
2. Calls `getSchema()` from `better-auth/db` to determine required tables/fields
|
|
92
|
+
3. Fetches current OData metadata via `db.getMetadata()`
|
|
93
|
+
4. Computes a diff: tables to create, fields to add to existing tables
|
|
94
|
+
5. Prints the migration plan and prompts for confirmation
|
|
95
|
+
6. Executes via `db.schema.createTable()` and `db.schema.addFields()`
|
|
96
|
+
|
|
97
|
+
Only schema is modified. No layouts or relationships are created.
|
|
98
|
+
|
|
99
|
+
If your runtime credentials lack Full Access, override for migration only:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npx @proofkit/better-auth migrate --username "admin" --password "admin_pass"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Skip confirmation with `-y`:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npx @proofkit/better-auth migrate -y
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 2. Adding plugins and re-migrating
|
|
112
|
+
|
|
113
|
+
When you add a Better Auth plugin (e.g. `twoFactor`, `organization`), it declares additional tables/fields. After updating `auth.ts`:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { betterAuth } from "better-auth";
|
|
117
|
+
import { twoFactor } from "better-auth/plugins";
|
|
118
|
+
import { FMServerConnection } from "@proofkit/fmodata";
|
|
119
|
+
import { FileMakerAdapter } from "@proofkit/better-auth";
|
|
120
|
+
|
|
121
|
+
const connection = new FMServerConnection({
|
|
122
|
+
serverUrl: process.env.FM_SERVER_URL!,
|
|
123
|
+
auth: {
|
|
124
|
+
username: process.env.FM_USERNAME!,
|
|
125
|
+
password: process.env.FM_PASSWORD!,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const db = connection.database(process.env.FM_DATABASE!);
|
|
130
|
+
|
|
131
|
+
export const auth = betterAuth({
|
|
132
|
+
database: FileMakerAdapter({ database: db }),
|
|
133
|
+
plugins: [twoFactor()],
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Re-run migration:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
npx @proofkit/better-auth migrate
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The planner diffs against existing metadata, so only new tables/fields are added. Existing tables are left untouched.
|
|
144
|
+
|
|
145
|
+
### 3. Troubleshooting privilege errors
|
|
146
|
+
|
|
147
|
+
When migration fails with OData error code `207`, the account lacks schema modification privileges. The CLI outputs:
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
Failed to create table "tableName": Cannot modify schema.
|
|
151
|
+
The account used does not have schema modification privileges.
|
|
152
|
+
Use --username and --password to provide Full Access credentials.
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Fix: provide Full Access credentials via CLI flags. These are only used for migration, not at runtime.
|
|
156
|
+
|
|
157
|
+
## Common Mistakes
|
|
158
|
+
|
|
159
|
+
### [CRITICAL] Using better-auth CLI instead of @proofkit/better-auth
|
|
160
|
+
|
|
161
|
+
Wrong:
|
|
162
|
+
```bash
|
|
163
|
+
npx better-auth migrate
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Correct:
|
|
167
|
+
```bash
|
|
168
|
+
npx @proofkit/better-auth migrate
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
The standard better-auth CLI does not know about the FileMaker adapter and produces: `ERROR [Better Auth]: filemaker is not supported. If it is a custom adapter, please request the maintainer to implement createSchema`. The `@proofkit/better-auth` CLI loads your auth config, extracts the `Database` instance from the adapter, and handles migration via fmodata's schema API.
|
|
172
|
+
|
|
173
|
+
Source: `apps/docs/content/docs/better-auth/troubleshooting.mdx`
|
|
174
|
+
|
|
175
|
+
### [HIGH] Missing Full Access credentials for schema migration
|
|
176
|
+
|
|
177
|
+
Wrong:
|
|
178
|
+
```bash
|
|
179
|
+
# Using runtime credentials that only have fmodata privilege
|
|
180
|
+
npx @proofkit/better-auth migrate
|
|
181
|
+
# Fails with OData error 207: Cannot modify schema
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Correct:
|
|
185
|
+
```bash
|
|
186
|
+
npx @proofkit/better-auth migrate --username "full_access_user" --password "full_access_pass"
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Schema modification (`db.schema.createTable`, `db.schema.addFields`) requires [Full Access] privileges. Standard API accounts with `fmodata` privilege can read/write data but cannot alter schema. The CLI accepts `--username` and `--password` flags to override credentials for migration only.
|
|
190
|
+
|
|
191
|
+
Source: `packages/better-auth/src/cli/index.ts`, `packages/better-auth/src/migrate.ts`
|
|
192
|
+
|
|
193
|
+
### [HIGH] Removing fields added by migration
|
|
194
|
+
|
|
195
|
+
Wrong:
|
|
196
|
+
```
|
|
197
|
+
Manually deleting "unused" fields from better-auth tables in FileMaker
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Correct:
|
|
201
|
+
```
|
|
202
|
+
Keep all fields created by migration, even if you don't plan to use them
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Better Auth expects all schema fields to exist at runtime. The adapter issues OData requests that reference these fields. Removing them causes runtime errors when Better Auth attempts to read or write those columns.
|
|
206
|
+
|
|
207
|
+
Source: `apps/docs/content/docs/better-auth/installation.mdx`
|
|
208
|
+
|
|
209
|
+
### [HIGH] Forgetting to re-run migration after adding plugins
|
|
210
|
+
|
|
211
|
+
Wrong:
|
|
212
|
+
```ts
|
|
213
|
+
// Added twoFactor() plugin to auth.ts but did not re-run migration
|
|
214
|
+
export const auth = betterAuth({
|
|
215
|
+
database: FileMakerAdapter({ database: db }),
|
|
216
|
+
plugins: [twoFactor()],
|
|
217
|
+
});
|
|
218
|
+
// Runtime errors: tables/fields for twoFactor don't exist
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Correct:
|
|
222
|
+
```bash
|
|
223
|
+
# After adding any plugin to auth.ts, always re-run:
|
|
224
|
+
npx @proofkit/better-auth migrate
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Each plugin declares additional tables and fields via `getSchema()`. The migration planner diffs the full schema (including plugins) against current OData metadata. Without re-running, the new tables/fields don't exist and Better Auth throws at runtime.
|
|
228
|
+
|
|
229
|
+
Source: `apps/docs/content/docs/better-auth/installation.mdx`
|
|
230
|
+
|
|
231
|
+
## References
|
|
232
|
+
|
|
233
|
+
- **fmodata-client** -- Better Auth uses fmodata `Database` under the hood for all OData requests. `FMServerConnection` and `database()` must be configured before `FileMakerAdapter` can work. The adapter calls `db._makeRequest()` for CRUD and `db.schema.*` for migrations.
|