@beignet/provider-auth-better-auth 0.0.1 → 0.0.3
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 +22 -0
- package/README.md +33 -30
- package/dist/index.d.ts +8 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +8 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @beignet/provider-auth-better-auth
|
|
2
2
|
|
|
3
|
+
## 0.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 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.
|
|
8
|
+
- Updated dependencies [3160184]
|
|
9
|
+
- Updated dependencies [254ef6d]
|
|
10
|
+
- Updated dependencies [4cb1784]
|
|
11
|
+
- Updated dependencies [8bd9085]
|
|
12
|
+
- @beignet/core@0.0.3
|
|
13
|
+
|
|
14
|
+
## 0.0.2
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [90b29ad]
|
|
19
|
+
- Updated dependencies [07fa19c]
|
|
20
|
+
- Updated dependencies [08bae67]
|
|
21
|
+
- Updated dependencies [730a818]
|
|
22
|
+
- Updated dependencies [a79f60c]
|
|
23
|
+
- @beignet/core@0.0.2
|
|
24
|
+
|
|
3
25
|
## 0.0.1
|
|
4
26
|
|
|
5
27
|
- Initial Beignet release under the `@beignet` npm scope.
|
package/README.md
CHANGED
|
@@ -115,37 +115,35 @@ export const server = await createNextServer({
|
|
|
115
115
|
});
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
-
### 4. Use the auth port in
|
|
118
|
+
### 4. Use the auth port in route hooks
|
|
119
119
|
|
|
120
|
-
Use `createAuthHooks(...)` to
|
|
121
|
-
`.meta({ auth: "required" })`:
|
|
120
|
+
Use `createAuthHooks(...)` to create route-scoped auth hooks:
|
|
122
121
|
|
|
123
122
|
```ts
|
|
124
123
|
// server/auth-hooks.ts
|
|
125
124
|
import { createAuthHooks } from "@beignet/core/server";
|
|
126
125
|
|
|
127
|
-
export const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
user: session
|
|
132
|
-
}
|
|
126
|
+
export const auth = createAuthHooks<AppContext, { user: CurrentUser }>({
|
|
127
|
+
resolve: async ({ ctx, req }) => {
|
|
128
|
+
const session = await ctx.ports.auth.getSession(req);
|
|
129
|
+
|
|
130
|
+
return session ? { user: session.user } : null;
|
|
131
|
+
},
|
|
133
132
|
});
|
|
134
133
|
```
|
|
135
134
|
|
|
136
|
-
Then
|
|
135
|
+
Then attach the hooks where routes are wired:
|
|
137
136
|
|
|
138
137
|
```ts
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
routes,
|
|
138
|
+
export const accountRoutes = defineRouteGroup<AppContext>()({
|
|
139
|
+
name: "account",
|
|
140
|
+
hooks: [auth.required()],
|
|
141
|
+
routes: [
|
|
142
|
+
{
|
|
143
|
+
contract: getProfile,
|
|
144
|
+
handle: async ({ ctx }) => getProfileUseCase.run({ ctx }),
|
|
145
|
+
},
|
|
146
|
+
],
|
|
149
147
|
});
|
|
150
148
|
```
|
|
151
149
|
|
|
@@ -266,13 +264,12 @@ function createAuthBetterAuthProvider<User = unknown, Session = unknown>(
|
|
|
266
264
|
|
|
267
265
|
## Advanced usage
|
|
268
266
|
|
|
269
|
-
###
|
|
267
|
+
### Route-scoped authentication
|
|
270
268
|
|
|
271
|
-
Use `createAuthHooks(...)` from `@beignet/core/server` to enforce
|
|
272
|
-
|
|
269
|
+
Use `createAuthHooks(...)` from `@beignet/core/server` to enforce auth beside
|
|
270
|
+
the contract-to-use-case wiring:
|
|
273
271
|
|
|
274
272
|
```ts
|
|
275
|
-
// Define a contract with auth metadata
|
|
276
273
|
const users = createContractGroup();
|
|
277
274
|
|
|
278
275
|
const getProfile = users
|
|
@@ -282,12 +279,18 @@ const getProfile = users
|
|
|
282
279
|
})
|
|
283
280
|
.meta({ auth: "required" });
|
|
284
281
|
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
user: session
|
|
290
|
-
}
|
|
282
|
+
const auth = createAuthHooks<AppContext, { user: CurrentUser }>({
|
|
283
|
+
resolve: async ({ ctx, req }) => {
|
|
284
|
+
const session = await ctx.ports.auth.getSession(req);
|
|
285
|
+
|
|
286
|
+
return session ? { user: session.user } : null;
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
export const userRoutes = defineRouteGroup<AppContext>()({
|
|
291
|
+
name: "users",
|
|
292
|
+
hooks: [auth.required()],
|
|
293
|
+
routes: [{ contract: getProfile, handle: getProfileHandler }],
|
|
291
294
|
});
|
|
292
295
|
```
|
|
293
296
|
|
package/dist/index.d.ts
CHANGED
|
@@ -52,22 +52,21 @@
|
|
|
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
|
|
63
|
-
* }
|
|
58
|
+
* const auth = createAuthHooks<AppContext, { user: CurrentUser }>({
|
|
59
|
+
* resolve: async ({ ctx, req }) => {
|
|
60
|
+
* const session = await ctx.ports.auth.getSession(req);
|
|
61
|
+
*
|
|
62
|
+
* return session ? { user: session.user } : null;
|
|
63
|
+
* },
|
|
64
64
|
* });
|
|
65
65
|
*
|
|
66
66
|
* const server = await createNextServer({
|
|
67
67
|
* ports: basePorts,
|
|
68
68
|
* providers: [createAuthBetterAuthProvider(auth)],
|
|
69
|
-
*
|
|
70
|
-
* createContext: async ({ ports }) => ({ ports, auth: null, user: null }),
|
|
69
|
+
* createContext: async ({ ports }) => ({ ports }),
|
|
71
70
|
* });
|
|
72
71
|
* ```
|
|
73
72
|
*/
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;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;;GAsItC"}
|
package/dist/index.js
CHANGED
|
@@ -52,22 +52,21 @@
|
|
|
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
|
|
63
|
-
* }
|
|
58
|
+
* const auth = createAuthHooks<AppContext, { user: CurrentUser }>({
|
|
59
|
+
* resolve: async ({ ctx, req }) => {
|
|
60
|
+
* const session = await ctx.ports.auth.getSession(req);
|
|
61
|
+
*
|
|
62
|
+
* return session ? { user: session.user } : null;
|
|
63
|
+
* },
|
|
64
64
|
* });
|
|
65
65
|
*
|
|
66
66
|
* const server = await createNextServer({
|
|
67
67
|
* ports: basePorts,
|
|
68
68
|
* providers: [createAuthBetterAuthProvider(auth)],
|
|
69
|
-
*
|
|
70
|
-
* createContext: async ({ ports }) => ({ ports, auth: null, user: null }),
|
|
69
|
+
* createContext: async ({ ports }) => ({ ports }),
|
|
71
70
|
* });
|
|
72
71
|
* ```
|
|
73
72
|
*/
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;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,U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I,EAAE,QAAQ,EAAE,EAAE,CAAC;QACvC,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -52,22 +52,21 @@
|
|
|
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
|
|
63
|
-
* }
|
|
58
|
+
* const auth = createAuthHooks<AppContext, { user: CurrentUser }>({
|
|
59
|
+
* resolve: async ({ ctx, req }) => {
|
|
60
|
+
* const session = await ctx.ports.auth.getSession(req);
|
|
61
|
+
*
|
|
62
|
+
* return session ? { user: session.user } : null;
|
|
63
|
+
* },
|
|
64
64
|
* });
|
|
65
65
|
*
|
|
66
66
|
* const server = await createNextServer({
|
|
67
67
|
* ports: basePorts,
|
|
68
68
|
* providers: [createAuthBetterAuthProvider(auth)],
|
|
69
|
-
*
|
|
70
|
-
* createContext: async ({ ports }) => ({ ports, auth: null, user: null }),
|
|
69
|
+
* createContext: async ({ ports }) => ({ ports }),
|
|
71
70
|
* });
|
|
72
71
|
* ```
|
|
73
72
|
*/
|