@beignet/provider-auth-better-auth 0.0.2 → 0.0.4
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/CHANGELOG.md +49 -0
- package/README.md +117 -48
- package/dist/index.d.ts +7 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -9
- package/dist/index.js.map +1 -1
- package/package.json +27 -6
- package/src/index.ts +6 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# @beignet/provider-auth-better-auth
|
|
2
2
|
|
|
3
|
+
## 0.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8bcb31f: Mark package READMEs with Beignet's experimental alpha status and 0.0.x stability expectations.
|
|
8
|
+
- 69b8c35: Repair a broken README code fence in the route-scoped authentication example and make the setup examples self-consistent: snippets that use the server context `gate` blueprint now register an app-owned gate port with `createGate(...)`.
|
|
9
|
+
- d137044: Declare `@beignet/core` as a peer dependency with a lockstep version range in
|
|
10
|
+
every integration and provider package instead of a regular `"*"` dependency.
|
|
11
|
+
Installs now always resolve a single shared copy of core, so `instanceof`
|
|
12
|
+
checks such as `isContractError` and upload error identity keep working, and
|
|
13
|
+
mixed Beignet versions fail loudly at install time instead of at runtime.
|
|
14
|
+
|
|
15
|
+
If your package manager does not install peer dependencies automatically, add
|
|
16
|
+
`@beignet/core` to your app alongside these packages. `@beignet/nuqs` now also
|
|
17
|
+
declares `@beignet/react-query` as a peer dependency, and
|
|
18
|
+
`@beignet/provider-storage-s3` now expects you to install
|
|
19
|
+
`@aws-sdk/client-s3` and `@aws-sdk/s3-request-presigner` yourself, matching
|
|
20
|
+
how other providers treat their SDKs.
|
|
21
|
+
|
|
22
|
+
- 603478f: Align package documentation with the canonical route registry and AppContext conventions.
|
|
23
|
+
- ac78cdf: Make `createAuthHooks` the single route-scoped auth hook API. The factory is
|
|
24
|
+
now curried — `createAuthHooks<AppContext>()({ resolve })` — so added context
|
|
25
|
+
fields are inferred from `resolve` instead of passed as a type argument, and a
|
|
26
|
+
new optional `headers` schema validates the raw lowercase request header
|
|
27
|
+
record before `resolve` runs, giving `resolve` typed credential headers
|
|
28
|
+
without contract casts. On `required()` hooks a header schema failure returns
|
|
29
|
+
a framework-owned 401; `optional()` hooks skip auth resolution; `public()`
|
|
30
|
+
hooks never parse headers. `defineRouteHook` (and the `RouteHookBuilder`
|
|
31
|
+
types) are removed — write non-auth route hooks as plain `RouteHook` object
|
|
32
|
+
literals.
|
|
33
|
+
- 1a79090: Emit Node-compatible ESM: all relative imports in published packages now carry explicit .js extensions, fixing ERR_MODULE_NOT_FOUND when running the CLI or importing package dist files under plain Node.
|
|
34
|
+
- 44f1192: Move first-party provider diagnostics to package-owned `beignet.provider`
|
|
35
|
+
manifest metadata and have doctor read installed provider package manifests.
|
|
36
|
+
- 2aa77ca: Add static provider metadata and provider wiring diagnostics for generated apps.
|
|
37
|
+
- 5b5dfb0: Pin the standard starter to a known-good Better Auth version, narrow provider metadata to avoid clean installs floating into incompatible Better Auth adapter dependencies, and add first-screen starter links for the todo workflow, health check, OpenAPI document, devtools, and docs.
|
|
38
|
+
- cca08b1: Align generated apps and package docs around the canonical auth, policy, and AppContext model.
|
|
39
|
+
- 8063d38: Rename the contract front door to `defineContract`/`defineContractGroup`, rename operational commands to tasks (`@beignet/core/tasks`, `defineTasks`, `runTask`, `beignet task run`, `beignet make task`, `server/tasks.ts`, `features/<feature>/tasks/`, `paths.tasks`), and standardize context binding: context-free declarations stay top-level (`defineEvent`), while context-bound definitions come from per-capability factories (`createListeners`, `createJobs`, `createSchedules`, `createNotifications`, `createTasks`) called once in `lib/`. Top-level context-generic `defineListener`, `defineJob`, `defineSchedule`, and `defineNotification` are removed.
|
|
40
|
+
|
|
41
|
+
## 0.0.3
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- 254ef6d: Add scoped route hooks for route and route-group policy, update auth hooks to expose public/optional/required route-hook factories, and teach CLI route inspection about curried route groups.
|
|
46
|
+
- Updated dependencies [3160184]
|
|
47
|
+
- Updated dependencies [254ef6d]
|
|
48
|
+
- Updated dependencies [4cb1784]
|
|
49
|
+
- Updated dependencies [8bd9085]
|
|
50
|
+
- @beignet/core@0.0.3
|
|
51
|
+
|
|
3
52
|
## 0.0.2
|
|
4
53
|
|
|
5
54
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# @beignet/provider-auth-better-auth
|
|
2
2
|
|
|
3
|
+
> [!CAUTION]
|
|
4
|
+
> Beignet is experimental alpha software. The `0.0.x` package line is for early
|
|
5
|
+
> evaluation, and APIs may change between releases while the framework settles.
|
|
6
|
+
|
|
3
7
|
Better Auth provider for Beignet applications.
|
|
4
8
|
|
|
5
9
|
The provider wraps an already-configured [Better Auth](https://better-auth.com)
|
|
@@ -27,9 +31,13 @@ schema, and auth routes.
|
|
|
27
31
|
## Install
|
|
28
32
|
|
|
29
33
|
```bash
|
|
30
|
-
bun add @beignet/core @beignet/provider-auth-better-auth better-auth
|
|
34
|
+
bun add @beignet/core @beignet/provider-auth-better-auth better-auth@1.6.11
|
|
31
35
|
```
|
|
32
36
|
|
|
37
|
+
The standard Beignet starter pins Better Auth to `1.6.11` so clean installs do
|
|
38
|
+
not float into incompatible transitive adapter versions. Revisit the pin when
|
|
39
|
+
upgrading Better Auth.
|
|
40
|
+
|
|
33
41
|
## Setup
|
|
34
42
|
|
|
35
43
|
### 1. Configure Better Auth in your app
|
|
@@ -99,53 +107,71 @@ export const providers = [
|
|
|
99
107
|
```ts
|
|
100
108
|
// server/index.ts
|
|
101
109
|
import { createNextServer } from "@beignet/next";
|
|
102
|
-
import {
|
|
110
|
+
import {
|
|
111
|
+
createAnonymousActor,
|
|
112
|
+
createGate,
|
|
113
|
+
createUserActor,
|
|
114
|
+
definePorts,
|
|
115
|
+
} from "@beignet/core/ports";
|
|
116
|
+
import type { AppContext } from "@/app-context";
|
|
103
117
|
import { routes } from "@/server/routes";
|
|
104
118
|
import { providers } from "./providers";
|
|
105
119
|
|
|
120
|
+
// App-owned authorization gate. Register feature policies here.
|
|
121
|
+
const gate = createGate({ policies: [] });
|
|
122
|
+
|
|
106
123
|
const appPorts = definePorts({
|
|
124
|
+
gate,
|
|
107
125
|
// add your app's other ports here
|
|
108
126
|
});
|
|
109
127
|
|
|
110
|
-
export const server = await createNextServer({
|
|
128
|
+
export const server = await createNextServer<AppContext>({
|
|
111
129
|
ports: appPorts,
|
|
112
130
|
providers,
|
|
113
|
-
|
|
131
|
+
context: {
|
|
132
|
+
gate: (ports) => ports.gate,
|
|
133
|
+
request: async ({ req, ports }) => {
|
|
134
|
+
const auth = await ports.auth.getSession(req);
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
actor: auth ? createUserActor(auth.user.id) : createAnonymousActor(),
|
|
138
|
+
auth,
|
|
139
|
+
requestId: req.headers.get("x-request-id") ?? crypto.randomUUID(),
|
|
140
|
+
ports,
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
},
|
|
114
144
|
routes,
|
|
115
145
|
});
|
|
116
146
|
```
|
|
117
147
|
|
|
118
|
-
### 4. Use the auth port in
|
|
148
|
+
### 4. Use the auth port in route hooks
|
|
119
149
|
|
|
120
|
-
Use `createAuthHooks(...)` to
|
|
121
|
-
`.meta({ auth: "required" })`:
|
|
150
|
+
Use `createAuthHooks(...)` to create route-scoped auth hooks:
|
|
122
151
|
|
|
123
152
|
```ts
|
|
124
153
|
// server/auth-hooks.ts
|
|
125
154
|
import { createAuthHooks } from "@beignet/core/server";
|
|
126
155
|
|
|
127
|
-
export const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
user: session?.user ?? null,
|
|
132
|
-
}),
|
|
156
|
+
export const auth = createAuthHooks<AppContext>()({
|
|
157
|
+
resolve: ({ ctx }) => {
|
|
158
|
+
return ctx.auth ? { user: ctx.auth.user } : null;
|
|
159
|
+
},
|
|
133
160
|
});
|
|
134
161
|
```
|
|
135
162
|
|
|
136
|
-
Then
|
|
163
|
+
Then attach the hooks where routes are wired:
|
|
137
164
|
|
|
138
165
|
```ts
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
routes,
|
|
166
|
+
export const accountRoutes = defineRouteGroup<AppContext>()({
|
|
167
|
+
name: "account",
|
|
168
|
+
hooks: [auth.required()],
|
|
169
|
+
routes: [
|
|
170
|
+
{
|
|
171
|
+
contract: getProfile,
|
|
172
|
+
handle: async ({ ctx }) => getProfileUseCase.run({ ctx }),
|
|
173
|
+
},
|
|
174
|
+
],
|
|
149
175
|
});
|
|
150
176
|
```
|
|
151
177
|
|
|
@@ -164,7 +190,7 @@ const UserProfileSchema = z.object({
|
|
|
164
190
|
email: z.string().email(),
|
|
165
191
|
});
|
|
166
192
|
|
|
167
|
-
const useCase = createUseCase<
|
|
193
|
+
const useCase = createUseCase<AppContext>();
|
|
168
194
|
|
|
169
195
|
export const getUserProfile = useCase
|
|
170
196
|
.query("users.profile")
|
|
@@ -177,7 +203,8 @@ export const getUserProfile = useCase
|
|
|
177
203
|
});
|
|
178
204
|
```
|
|
179
205
|
|
|
180
|
-
In the standard app shape, `
|
|
206
|
+
In the standard app shape, the server's `context.request` factory reads the
|
|
207
|
+
request once with
|
|
181
208
|
`ctx.ports.auth.getSession(req)` and stores the result on `ctx.auth`. Use cases
|
|
182
209
|
then call an app-owned helper such as `requireUser(ctx)` instead of depending
|
|
183
210
|
on the raw request.
|
|
@@ -266,14 +293,13 @@ function createAuthBetterAuthProvider<User = unknown, Session = unknown>(
|
|
|
266
293
|
|
|
267
294
|
## Advanced usage
|
|
268
295
|
|
|
269
|
-
###
|
|
296
|
+
### Route-scoped authentication
|
|
270
297
|
|
|
271
|
-
Use `createAuthHooks(...)` from `@beignet/core/server` to enforce
|
|
272
|
-
|
|
298
|
+
Use `createAuthHooks(...)` from `@beignet/core/server` to enforce auth beside
|
|
299
|
+
the contract-to-use-case wiring:
|
|
273
300
|
|
|
274
301
|
```ts
|
|
275
|
-
|
|
276
|
-
const users = createContractGroup();
|
|
302
|
+
const users = defineContractGroup();
|
|
277
303
|
|
|
278
304
|
const getProfile = users
|
|
279
305
|
.get("/api/profile")
|
|
@@ -282,12 +308,16 @@ const getProfile = users
|
|
|
282
308
|
})
|
|
283
309
|
.meta({ auth: "required" });
|
|
284
310
|
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
311
|
+
const auth = createAuthHooks<AppContext>()({
|
|
312
|
+
resolve: ({ ctx }) => {
|
|
313
|
+
return ctx.auth ? { user: ctx.auth.user } : null;
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
export const userRoutes = defineRouteGroup<AppContext>()({
|
|
318
|
+
name: "users",
|
|
319
|
+
hooks: [auth.required()],
|
|
320
|
+
routes: [{ contract: getProfile, handle: getProfileHandler }],
|
|
291
321
|
});
|
|
292
322
|
```
|
|
293
323
|
|
|
@@ -366,17 +396,39 @@ See the [Better Auth documentation](https://better-auth.com) for details on rout
|
|
|
366
396
|
```ts
|
|
367
397
|
import { betterAuth } from "better-auth";
|
|
368
398
|
import { createNextServer } from "@beignet/next";
|
|
369
|
-
import {
|
|
399
|
+
import {
|
|
400
|
+
createAnonymousActor,
|
|
401
|
+
createGate,
|
|
402
|
+
createUserActor,
|
|
403
|
+
definePorts,
|
|
404
|
+
} from "@beignet/core/ports";
|
|
370
405
|
import { createAuthBetterAuthProvider } from "@beignet/provider-auth-better-auth";
|
|
406
|
+
import type { AppContext } from "@/app-context";
|
|
371
407
|
import { routes } from "@/server/routes";
|
|
372
408
|
|
|
373
409
|
const auth = betterAuth({ database: db });
|
|
374
|
-
const appPorts = definePorts({});
|
|
375
410
|
|
|
376
|
-
|
|
411
|
+
// App-owned authorization gate. Register feature policies here.
|
|
412
|
+
const gate = createGate({ policies: [] });
|
|
413
|
+
|
|
414
|
+
const appPorts = definePorts({ gate });
|
|
415
|
+
|
|
416
|
+
const server = await createNextServer<AppContext>({
|
|
377
417
|
ports: appPorts,
|
|
378
418
|
providers: [createAuthBetterAuthProvider(auth)],
|
|
379
|
-
|
|
419
|
+
context: {
|
|
420
|
+
gate: (ports) => ports.gate,
|
|
421
|
+
request: async ({ req, ports }) => {
|
|
422
|
+
const auth = await ports.auth.getSession(req);
|
|
423
|
+
|
|
424
|
+
return {
|
|
425
|
+
actor: auth ? createUserActor(auth.user.id) : createAnonymousActor(),
|
|
426
|
+
auth,
|
|
427
|
+
requestId: req.headers.get("x-request-id") ?? crypto.randomUUID(),
|
|
428
|
+
ports,
|
|
429
|
+
};
|
|
430
|
+
},
|
|
431
|
+
},
|
|
380
432
|
routes,
|
|
381
433
|
});
|
|
382
434
|
```
|
|
@@ -384,19 +436,36 @@ const server = await createNextServer({
|
|
|
384
436
|
### Protecting routes
|
|
385
437
|
|
|
386
438
|
```ts
|
|
439
|
+
import { AuthUnauthorizedError } from "@beignet/core/ports";
|
|
440
|
+
|
|
387
441
|
const authHook = {
|
|
388
442
|
name: "auth",
|
|
389
|
-
beforeHandle: async ({
|
|
390
|
-
|
|
391
|
-
|
|
443
|
+
beforeHandle: async ({ ctx }) => {
|
|
444
|
+
if (!ctx.auth) {
|
|
445
|
+
throw new AuthUnauthorizedError();
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return { ctx: { ...ctx, user: ctx.auth.user } };
|
|
392
449
|
},
|
|
393
450
|
};
|
|
394
451
|
|
|
395
|
-
const server = await createNextServer({
|
|
452
|
+
const server = await createNextServer<AppContext>({
|
|
396
453
|
ports: appPorts,
|
|
397
454
|
providers: [createAuthBetterAuthProvider(auth)],
|
|
398
455
|
hooks: [authHook],
|
|
399
|
-
|
|
456
|
+
context: {
|
|
457
|
+
gate: (ports) => ports.gate,
|
|
458
|
+
request: async ({ req, ports }) => {
|
|
459
|
+
const auth = await ports.auth.getSession(req);
|
|
460
|
+
|
|
461
|
+
return {
|
|
462
|
+
actor: auth ? createUserActor(auth.user.id) : createAnonymousActor(),
|
|
463
|
+
auth,
|
|
464
|
+
requestId: req.headers.get("x-request-id") ?? crypto.randomUUID(),
|
|
465
|
+
ports,
|
|
466
|
+
};
|
|
467
|
+
},
|
|
468
|
+
},
|
|
400
469
|
routes,
|
|
401
470
|
});
|
|
402
471
|
```
|
|
@@ -404,8 +473,8 @@ const server = await createNextServer({
|
|
|
404
473
|
### Optional authentication
|
|
405
474
|
|
|
406
475
|
```ts
|
|
407
|
-
const listData = async ({
|
|
408
|
-
const user =
|
|
476
|
+
const listData = async ({ ctx }) => {
|
|
477
|
+
const user = ctx.auth?.user;
|
|
409
478
|
|
|
410
479
|
if (user) {
|
|
411
480
|
return {
|
package/dist/index.d.ts
CHANGED
|
@@ -52,22 +52,19 @@
|
|
|
52
52
|
* ],
|
|
53
53
|
* });
|
|
54
54
|
*
|
|
55
|
-
* // 4. Use the auth port through
|
|
55
|
+
* // 4. Use the auth port through route-scoped auth hooks
|
|
56
56
|
* import { createAuthHooks } from "@beignet/core/server";
|
|
57
57
|
*
|
|
58
|
-
* const
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* user: session?.user ?? null,
|
|
63
|
-
* }),
|
|
58
|
+
* const auth = createAuthHooks<AppContext>()({
|
|
59
|
+
* resolve: ({ ctx }) => {
|
|
60
|
+
* return ctx.auth ? { user: ctx.auth.user } : null;
|
|
61
|
+
* },
|
|
64
62
|
* });
|
|
65
63
|
*
|
|
66
64
|
* const server = await createNextServer({
|
|
67
65
|
* ports: basePorts,
|
|
68
66
|
* providers: [createAuthBetterAuthProvider(auth)],
|
|
69
|
-
*
|
|
70
|
-
* createContext: async ({ ports }) => ({ ports, auth: null, user: null }),
|
|
67
|
+
* context: async ({ ports }) => ({ ports }),
|
|
71
68
|
* });
|
|
72
69
|
* ```
|
|
73
70
|
*/
|
|
@@ -126,5 +123,5 @@ export type BetterAuthServer<User = unknown, Session = unknown> = {
|
|
|
126
123
|
*/
|
|
127
124
|
export declare function createAuthBetterAuthProvider<User = unknown, Session = unknown>(auth: BetterAuthServer<User, Session>): import("@beignet/core/providers").ServiceProvider<unknown, import("@standard-schema/spec").StandardSchemaV1<void, void>, {
|
|
128
125
|
auth: AuthPort<User, Session, AuthRequestLike>;
|
|
129
|
-
}>;
|
|
126
|
+
}, unknown, void>;
|
|
130
127
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AAEH,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,eAAe,EAErB,MAAM,qBAAqB,CAAC;AAM7B;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,CAAC,IAAI,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI;IAChE;;;OAGG;IACH,GAAG,EAAE;QACH;;;;WAIG;QACH,UAAU,CAAC,OAAO,EAAE;YAClB,OAAO,EAAE,OAAO,CAAC;SAClB,GAAG,OAAO,CAAC;YAAE,IAAI,EAAE,IAAI,CAAC;YAAC,OAAO,EAAE,OAAO,CAAA;SAAE,GAAG,IAAI,CAAC,CAAC;KACtD,CAAC;CACH,CAAC;AAMF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EAC5E,IAAI,EAAE,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC;;kBAsItC"}
|
package/dist/index.js
CHANGED
|
@@ -52,22 +52,19 @@
|
|
|
52
52
|
* ],
|
|
53
53
|
* });
|
|
54
54
|
*
|
|
55
|
-
* // 4. Use the auth port through
|
|
55
|
+
* // 4. Use the auth port through route-scoped auth hooks
|
|
56
56
|
* import { createAuthHooks } from "@beignet/core/server";
|
|
57
57
|
*
|
|
58
|
-
* const
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* user: session?.user ?? null,
|
|
63
|
-
* }),
|
|
58
|
+
* const auth = createAuthHooks<AppContext>()({
|
|
59
|
+
* resolve: ({ ctx }) => {
|
|
60
|
+
* return ctx.auth ? { user: ctx.auth.user } : null;
|
|
61
|
+
* },
|
|
64
62
|
* });
|
|
65
63
|
*
|
|
66
64
|
* const server = await createNextServer({
|
|
67
65
|
* ports: basePorts,
|
|
68
66
|
* providers: [createAuthBetterAuthProvider(auth)],
|
|
69
|
-
*
|
|
70
|
-
* createContext: async ({ ports }) => ({ ports, auth: null, user: null }),
|
|
67
|
+
* context: async ({ ports }) => ({ ports }),
|
|
71
68
|
* });
|
|
72
69
|
* ```
|
|
73
70
|
*/
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AAEH,OAAO,EAGL,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,cAAc,EACd,6BAA6B,GAC9B,MAAM,yBAAyB,CAAC;AA0BjC,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAA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AAC;wBACH,MAAM,KAAK,CAAC;oBACd,CAAC;gBACH,CAAC;aACF,CAAC;YAEF,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC;QACvC,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beignet/provider-auth-better-auth",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Better Auth provider for Beignet - adds auth port for authentication and session management",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -54,16 +54,37 @@
|
|
|
54
54
|
"node": ">=18.0.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
"dependencies": {
|
|
60
|
-
"@beignet/core": "*"
|
|
57
|
+
"@beignet/core": ">=0.0.3 <1.0.0",
|
|
58
|
+
"better-auth": ">=1.3.26 <1.6.14"
|
|
61
59
|
},
|
|
62
60
|
"devDependencies": {
|
|
63
61
|
"@beignet/devtools": "*",
|
|
64
62
|
"@types/bun": "^1.3.13",
|
|
65
63
|
"@types/node": "^20.10.0",
|
|
66
|
-
"better-auth": "
|
|
64
|
+
"better-auth": "1.6.11",
|
|
67
65
|
"typescript": "^5.3.0"
|
|
66
|
+
},
|
|
67
|
+
"beignet": {
|
|
68
|
+
"provider": {
|
|
69
|
+
"displayName": "Better Auth provider",
|
|
70
|
+
"ports": [
|
|
71
|
+
"auth"
|
|
72
|
+
],
|
|
73
|
+
"appPorts": [
|
|
74
|
+
{
|
|
75
|
+
"name": "auth",
|
|
76
|
+
"type": "AuthPort"
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
"watchers": [
|
|
80
|
+
"auth"
|
|
81
|
+
],
|
|
82
|
+
"registration": {
|
|
83
|
+
"required": true,
|
|
84
|
+
"tokens": [
|
|
85
|
+
"createAuthBetterAuthProvider"
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
68
89
|
}
|
|
69
90
|
}
|
package/src/index.ts
CHANGED
|
@@ -52,22 +52,19 @@
|
|
|
52
52
|
* ],
|
|
53
53
|
* });
|
|
54
54
|
*
|
|
55
|
-
* // 4. Use the auth port through
|
|
55
|
+
* // 4. Use the auth port through route-scoped auth hooks
|
|
56
56
|
* import { createAuthHooks } from "@beignet/core/server";
|
|
57
57
|
*
|
|
58
|
-
* const
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* user: session?.user ?? null,
|
|
63
|
-
* }),
|
|
58
|
+
* const auth = createAuthHooks<AppContext>()({
|
|
59
|
+
* resolve: ({ ctx }) => {
|
|
60
|
+
* return ctx.auth ? { user: ctx.auth.user } : null;
|
|
61
|
+
* },
|
|
64
62
|
* });
|
|
65
63
|
*
|
|
66
64
|
* const server = await createNextServer({
|
|
67
65
|
* ports: basePorts,
|
|
68
66
|
* providers: [createAuthBetterAuthProvider(auth)],
|
|
69
|
-
*
|
|
70
|
-
* createContext: async ({ ports }) => ({ ports, auth: null, user: null }),
|
|
67
|
+
* context: async ({ ports }) => ({ ports }),
|
|
71
68
|
* });
|
|
72
69
|
* ```
|
|
73
70
|
*/
|