@beignet/provider-auth-better-auth 0.0.3 → 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 +38 -0
- package/README.md +94 -28
- package/dist/index.d.ts +5 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -6
- package/dist/index.js.map +1 -1
- package/package.json +27 -6
- package/src/index.ts +4 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
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
|
+
|
|
3
41
|
## 0.0.3
|
|
4
42
|
|
|
5
43
|
### 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,18 +107,40 @@ 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
|
```
|
|
@@ -123,11 +153,9 @@ Use `createAuthHooks(...)` to create route-scoped auth hooks:
|
|
|
123
153
|
// server/auth-hooks.ts
|
|
124
154
|
import { createAuthHooks } from "@beignet/core/server";
|
|
125
155
|
|
|
126
|
-
export const auth = createAuthHooks<AppContext
|
|
127
|
-
resolve:
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return session ? { user: session.user } : null;
|
|
156
|
+
export const auth = createAuthHooks<AppContext>()({
|
|
157
|
+
resolve: ({ ctx }) => {
|
|
158
|
+
return ctx.auth ? { user: ctx.auth.user } : null;
|
|
131
159
|
},
|
|
132
160
|
});
|
|
133
161
|
```
|
|
@@ -162,7 +190,7 @@ const UserProfileSchema = z.object({
|
|
|
162
190
|
email: z.string().email(),
|
|
163
191
|
});
|
|
164
192
|
|
|
165
|
-
const useCase = createUseCase<
|
|
193
|
+
const useCase = createUseCase<AppContext>();
|
|
166
194
|
|
|
167
195
|
export const getUserProfile = useCase
|
|
168
196
|
.query("users.profile")
|
|
@@ -175,7 +203,8 @@ export const getUserProfile = useCase
|
|
|
175
203
|
});
|
|
176
204
|
```
|
|
177
205
|
|
|
178
|
-
In the standard app shape, `
|
|
206
|
+
In the standard app shape, the server's `context.request` factory reads the
|
|
207
|
+
request once with
|
|
179
208
|
`ctx.ports.auth.getSession(req)` and stores the result on `ctx.auth`. Use cases
|
|
180
209
|
then call an app-owned helper such as `requireUser(ctx)` instead of depending
|
|
181
210
|
on the raw request.
|
|
@@ -270,7 +299,7 @@ Use `createAuthHooks(...)` from `@beignet/core/server` to enforce auth beside
|
|
|
270
299
|
the contract-to-use-case wiring:
|
|
271
300
|
|
|
272
301
|
```ts
|
|
273
|
-
const users =
|
|
302
|
+
const users = defineContractGroup();
|
|
274
303
|
|
|
275
304
|
const getProfile = users
|
|
276
305
|
.get("/api/profile")
|
|
@@ -279,11 +308,9 @@ const getProfile = users
|
|
|
279
308
|
})
|
|
280
309
|
.meta({ auth: "required" });
|
|
281
310
|
|
|
282
|
-
const auth = createAuthHooks<AppContext
|
|
283
|
-
resolve:
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
return session ? { user: session.user } : null;
|
|
311
|
+
const auth = createAuthHooks<AppContext>()({
|
|
312
|
+
resolve: ({ ctx }) => {
|
|
313
|
+
return ctx.auth ? { user: ctx.auth.user } : null;
|
|
287
314
|
},
|
|
288
315
|
});
|
|
289
316
|
|
|
@@ -369,17 +396,39 @@ See the [Better Auth documentation](https://better-auth.com) for details on rout
|
|
|
369
396
|
```ts
|
|
370
397
|
import { betterAuth } from "better-auth";
|
|
371
398
|
import { createNextServer } from "@beignet/next";
|
|
372
|
-
import {
|
|
399
|
+
import {
|
|
400
|
+
createAnonymousActor,
|
|
401
|
+
createGate,
|
|
402
|
+
createUserActor,
|
|
403
|
+
definePorts,
|
|
404
|
+
} from "@beignet/core/ports";
|
|
373
405
|
import { createAuthBetterAuthProvider } from "@beignet/provider-auth-better-auth";
|
|
406
|
+
import type { AppContext } from "@/app-context";
|
|
374
407
|
import { routes } from "@/server/routes";
|
|
375
408
|
|
|
376
409
|
const auth = betterAuth({ database: db });
|
|
377
|
-
const appPorts = definePorts({});
|
|
378
410
|
|
|
379
|
-
|
|
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>({
|
|
380
417
|
ports: appPorts,
|
|
381
418
|
providers: [createAuthBetterAuthProvider(auth)],
|
|
382
|
-
|
|
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
|
+
},
|
|
383
432
|
routes,
|
|
384
433
|
});
|
|
385
434
|
```
|
|
@@ -387,19 +436,36 @@ const server = await createNextServer({
|
|
|
387
436
|
### Protecting routes
|
|
388
437
|
|
|
389
438
|
```ts
|
|
439
|
+
import { AuthUnauthorizedError } from "@beignet/core/ports";
|
|
440
|
+
|
|
390
441
|
const authHook = {
|
|
391
442
|
name: "auth",
|
|
392
|
-
beforeHandle: async ({
|
|
393
|
-
|
|
394
|
-
|
|
443
|
+
beforeHandle: async ({ ctx }) => {
|
|
444
|
+
if (!ctx.auth) {
|
|
445
|
+
throw new AuthUnauthorizedError();
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return { ctx: { ...ctx, user: ctx.auth.user } };
|
|
395
449
|
},
|
|
396
450
|
};
|
|
397
451
|
|
|
398
|
-
const server = await createNextServer({
|
|
452
|
+
const server = await createNextServer<AppContext>({
|
|
399
453
|
ports: appPorts,
|
|
400
454
|
providers: [createAuthBetterAuthProvider(auth)],
|
|
401
455
|
hooks: [authHook],
|
|
402
|
-
|
|
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
|
+
},
|
|
403
469
|
routes,
|
|
404
470
|
});
|
|
405
471
|
```
|
|
@@ -407,8 +473,8 @@ const server = await createNextServer({
|
|
|
407
473
|
### Optional authentication
|
|
408
474
|
|
|
409
475
|
```ts
|
|
410
|
-
const listData = async ({
|
|
411
|
-
const user =
|
|
476
|
+
const listData = async ({ ctx }) => {
|
|
477
|
+
const user = ctx.auth?.user;
|
|
412
478
|
|
|
413
479
|
if (user) {
|
|
414
480
|
return {
|
package/dist/index.d.ts
CHANGED
|
@@ -55,18 +55,16 @@
|
|
|
55
55
|
* // 4. Use the auth port through route-scoped auth hooks
|
|
56
56
|
* import { createAuthHooks } from "@beignet/core/server";
|
|
57
57
|
*
|
|
58
|
-
* const auth = createAuthHooks<AppContext
|
|
59
|
-
* resolve:
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* return session ? { user: session.user } : null;
|
|
58
|
+
* const auth = createAuthHooks<AppContext>()({
|
|
59
|
+
* resolve: ({ ctx }) => {
|
|
60
|
+
* return ctx.auth ? { user: ctx.auth.user } : null;
|
|
63
61
|
* },
|
|
64
62
|
* });
|
|
65
63
|
*
|
|
66
64
|
* const server = await createNextServer({
|
|
67
65
|
* ports: basePorts,
|
|
68
66
|
* providers: [createAuthBetterAuthProvider(auth)],
|
|
69
|
-
*
|
|
67
|
+
* context: async ({ ports }) => ({ ports }),
|
|
70
68
|
* });
|
|
71
69
|
* ```
|
|
72
70
|
*/
|
|
@@ -125,5 +123,5 @@ export type BetterAuthServer<User = unknown, Session = unknown> = {
|
|
|
125
123
|
*/
|
|
126
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>, {
|
|
127
125
|
auth: AuthPort<User, Session, AuthRequestLike>;
|
|
128
|
-
}>;
|
|
126
|
+
}, unknown, void>;
|
|
129
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
|
@@ -55,18 +55,16 @@
|
|
|
55
55
|
* // 4. Use the auth port through route-scoped auth hooks
|
|
56
56
|
* import { createAuthHooks } from "@beignet/core/server";
|
|
57
57
|
*
|
|
58
|
-
* const auth = createAuthHooks<AppContext
|
|
59
|
-
* resolve:
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* return session ? { user: session.user } : null;
|
|
58
|
+
* const auth = createAuthHooks<AppContext>()({
|
|
59
|
+
* resolve: ({ ctx }) => {
|
|
60
|
+
* return ctx.auth ? { user: ctx.auth.user } : null;
|
|
63
61
|
* },
|
|
64
62
|
* });
|
|
65
63
|
*
|
|
66
64
|
* const server = await createNextServer({
|
|
67
65
|
* ports: basePorts,
|
|
68
66
|
* providers: [createAuthBetterAuthProvider(auth)],
|
|
69
|
-
*
|
|
67
|
+
* context: async ({ ports }) => ({ ports }),
|
|
70
68
|
* });
|
|
71
69
|
* ```
|
|
72
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,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,4BAA4B,CAC1C,IAAqC;IAErC,OAAO,cAAc,CAAC;QACpB,IAAI,EAAE,kBAAkB;QAExB,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE;YACnB,MAAM,eAAe,GAAG,6BAA6B,CAAC,KAAK,EAAE;gBAC3D,YAAY,EAAE,kBAAkB;gBACh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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
|
@@ -55,18 +55,16 @@
|
|
|
55
55
|
* // 4. Use the auth port through route-scoped auth hooks
|
|
56
56
|
* import { createAuthHooks } from "@beignet/core/server";
|
|
57
57
|
*
|
|
58
|
-
* const auth = createAuthHooks<AppContext
|
|
59
|
-
* resolve:
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* return session ? { user: session.user } : null;
|
|
58
|
+
* const auth = createAuthHooks<AppContext>()({
|
|
59
|
+
* resolve: ({ ctx }) => {
|
|
60
|
+
* return ctx.auth ? { user: ctx.auth.user } : null;
|
|
63
61
|
* },
|
|
64
62
|
* });
|
|
65
63
|
*
|
|
66
64
|
* const server = await createNextServer({
|
|
67
65
|
* ports: basePorts,
|
|
68
66
|
* providers: [createAuthBetterAuthProvider(auth)],
|
|
69
|
-
*
|
|
67
|
+
* context: async ({ ports }) => ({ ports }),
|
|
70
68
|
* });
|
|
71
69
|
* ```
|
|
72
70
|
*/
|