@fougere/auth-better 0.5.0-alpha.1 → 0.7.0-alpha.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/README.md +1 -1
- package/dist/adapter.d.ts +5 -11
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +37 -48
- package/dist/adapter.js.map +1 -1
- package/dist/entities.d.ts +1 -7
- package/dist/entities.d.ts.map +1 -1
- package/dist/entities.js +1 -7
- package/dist/entities.js.map +1 -1
- package/dist/index.d.ts +2 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -20
- package/dist/index.js.map +1 -1
- package/dist/translate.d.ts +2 -12
- package/dist/translate.d.ts.map +1 -1
- package/dist/translate.js +1 -5
- package/dist/translate.js.map +1 -1
- package/package.json +4 -4
- package/src/adapter.ts +40 -51
- package/src/entities.ts +2 -24
- package/src/index.ts +11 -29
- package/src/translate.ts +2 -12
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @fougere/auth-better
|
|
2
2
|
> Fougere's auth
|
|
3
3
|
A translation layer onto [better-auth](https://better-auth.com): its writes go through
|
|
4
|
-
Fougere's
|
|
4
|
+
Fougere's storage, and the application's `User` stays its own — Session and Account are
|
|
5
5
|
built against it.
|
|
6
6
|
|
|
7
7
|
## Installation
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Storage } from '@fougere/core';
|
|
2
2
|
/**
|
|
3
3
|
* Map of better-auth model names ('user', 'session', 'account', ...)
|
|
4
|
-
* to Fougere
|
|
4
|
+
* to Fougere Storage instances. Built once at boot by create() in index.ts.
|
|
5
5
|
*/
|
|
6
|
-
export type
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
* This closes the loop: the same `db` resolved by Fougere's bootstrap is the
|
|
11
|
-
* one EntityOrm writes to, and better-auth never touches the storage directly.
|
|
12
|
-
* If Fougere swaps Kysely for another backend, this adapter follows for free.
|
|
13
|
-
*/
|
|
14
|
-
export declare function fougereAdapter(ormMap: OrmMap): import("better-auth/adapters").AdapterFactory<import("better-auth").BetterAuthOptions>;
|
|
6
|
+
export type StorageMap = Map<string, Storage>;
|
|
7
|
+
/** Better-auth adapter that routes every operation through Fougere Storage. */
|
|
8
|
+
export declare function fougereAdapter(storageMap: StorageMap): import("better-auth/adapters").AdapterFactory<import("better-auth").BetterAuthOptions>;
|
|
15
9
|
//# sourceMappingURL=adapter.d.ts.map
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAgC9C,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,0FAyGpD"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { createAdapterFactory } from 'better-auth/adapters';
|
|
2
|
-
/**
|
|
3
|
-
* Where[] supported subset:
|
|
4
|
-
* - All clauses use 'eq' operator
|
|
5
|
-
* - Implicit AND between clauses (no OR connector)
|
|
6
|
-
* Anything else throws — extend EntityOrm or add an engine-level fallback when needed.
|
|
7
|
-
*/
|
|
2
|
+
/** Where[] supported subset. */
|
|
8
3
|
function whereToCriteria(where) {
|
|
9
4
|
const criteria = {};
|
|
10
5
|
for (const clause of where) {
|
|
@@ -19,23 +14,17 @@ function whereToCriteria(where) {
|
|
|
19
14
|
}
|
|
20
15
|
return criteria;
|
|
21
16
|
}
|
|
22
|
-
function
|
|
23
|
-
const
|
|
24
|
-
if (!
|
|
17
|
+
function storageOf(storageMap, model) {
|
|
18
|
+
const storage = storageMap.get(model);
|
|
19
|
+
if (!storage) {
|
|
25
20
|
throw new Error(`[fougereAdapter] Unknown model '${model}'. ` +
|
|
26
|
-
`Known models: ${[...
|
|
21
|
+
`Known models: ${[...storageMap.keys()].join(', ')}. ` +
|
|
27
22
|
`Plugins that ship their own schema need entities registered explicitly.`);
|
|
28
23
|
}
|
|
29
|
-
return
|
|
24
|
+
return storage;
|
|
30
25
|
}
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
*
|
|
34
|
-
* This closes the loop: the same `db` resolved by Fougere's bootstrap is the
|
|
35
|
-
* one EntityOrm writes to, and better-auth never touches the storage directly.
|
|
36
|
-
* If Fougere swaps Kysely for another backend, this adapter follows for free.
|
|
37
|
-
*/
|
|
38
|
-
export function fougereAdapter(ormMap) {
|
|
26
|
+
/** Better-auth adapter that routes every operation through Fougere Storage. */
|
|
27
|
+
export function fougereAdapter(storageMap) {
|
|
39
28
|
return createAdapterFactory({
|
|
40
29
|
config: {
|
|
41
30
|
adapterId: 'fougere',
|
|
@@ -43,34 +32,34 @@ export function fougereAdapter(ormMap) {
|
|
|
43
32
|
usePlural: false,
|
|
44
33
|
supportsArrays: false,
|
|
45
34
|
supportsJSON: false,
|
|
46
|
-
// The
|
|
35
|
+
// The storage converts both ways now (`schema-sql/src/values.ts`), so better-auth
|
|
47
36
|
// can hand over the Dates and booleans its own types declare.
|
|
48
37
|
supportsDates: true,
|
|
49
38
|
supportsBooleans: true,
|
|
50
39
|
},
|
|
51
40
|
adapter: () => ({
|
|
52
41
|
create: async ({ model, data }) => {
|
|
53
|
-
const
|
|
54
|
-
return (await
|
|
42
|
+
const storage = storageOf(storageMap, model);
|
|
43
|
+
return (await storage.create(data));
|
|
55
44
|
},
|
|
56
45
|
findOne: async ({ model, where }) => {
|
|
57
|
-
const
|
|
46
|
+
const storage = storageOf(storageMap, model);
|
|
58
47
|
const criteria = whereToCriteria(where);
|
|
59
48
|
if (Object.keys(criteria).length === 1 && 'id' in criteria) {
|
|
60
|
-
const found = await
|
|
49
|
+
const found = await storage.findById(criteria.id);
|
|
61
50
|
return (found ?? null);
|
|
62
51
|
}
|
|
63
|
-
const found = await
|
|
52
|
+
const found = await storage.findBy(criteria);
|
|
64
53
|
return (found ?? null);
|
|
65
54
|
},
|
|
66
55
|
findMany: async ({ model, where, limit, offset, sortBy, }) => {
|
|
67
|
-
const
|
|
56
|
+
const storage = storageOf(storageMap, model);
|
|
68
57
|
if (where && where.length > 0) {
|
|
69
58
|
const criteria = whereToCriteria(where);
|
|
70
|
-
const rows = await
|
|
59
|
+
const rows = await storage.findAllBy(criteria);
|
|
71
60
|
return applyClientSidePagination(rows, sortBy, offset, limit);
|
|
72
61
|
}
|
|
73
|
-
const rows = await
|
|
62
|
+
const rows = await storage.list({
|
|
74
63
|
limit,
|
|
75
64
|
offset,
|
|
76
65
|
orderBy: sortBy?.field,
|
|
@@ -79,59 +68,59 @@ export function fougereAdapter(ormMap) {
|
|
|
79
68
|
return rows;
|
|
80
69
|
},
|
|
81
70
|
count: async ({ model, where }) => {
|
|
82
|
-
const
|
|
71
|
+
const storage = storageOf(storageMap, model);
|
|
83
72
|
if (where && where.length > 0) {
|
|
84
73
|
const criteria = whereToCriteria(where);
|
|
85
|
-
const rows = await
|
|
74
|
+
const rows = await storage.findAllBy(criteria);
|
|
86
75
|
return rows.length;
|
|
87
76
|
}
|
|
88
|
-
const rows = await
|
|
77
|
+
const rows = await storage.list({ count: true });
|
|
89
78
|
return rows.total ?? rows.length;
|
|
90
79
|
},
|
|
91
80
|
update: async ({ model, where, update }) => {
|
|
92
|
-
const
|
|
81
|
+
const storage = storageOf(storageMap, model);
|
|
93
82
|
const criteria = whereToCriteria(where);
|
|
94
83
|
const target = 'id' in criteria
|
|
95
|
-
? await
|
|
96
|
-
: await
|
|
84
|
+
? await storage.findById(criteria.id)
|
|
85
|
+
: await storage.findBy(criteria);
|
|
97
86
|
if (!target)
|
|
98
87
|
return null;
|
|
99
|
-
return (await
|
|
88
|
+
return (await storage.update(target.id, update));
|
|
100
89
|
},
|
|
101
90
|
updateMany: async ({ model, where, update }) => {
|
|
102
|
-
const
|
|
91
|
+
const storage = storageOf(storageMap, model);
|
|
103
92
|
const criteria = whereToCriteria(where);
|
|
104
|
-
const targets = await
|
|
93
|
+
const targets = await storage.findAllBy(criteria);
|
|
105
94
|
for (const target of targets)
|
|
106
|
-
await
|
|
95
|
+
await storage.update(target.id, update);
|
|
107
96
|
return targets.length;
|
|
108
97
|
},
|
|
109
98
|
delete: async ({ model, where }) => {
|
|
110
|
-
const
|
|
99
|
+
const storage = storageOf(storageMap, model);
|
|
111
100
|
const criteria = whereToCriteria(where);
|
|
112
101
|
const target = 'id' in criteria
|
|
113
|
-
? await
|
|
114
|
-
: await
|
|
102
|
+
? await storage.findById(criteria.id)
|
|
103
|
+
: await storage.findBy(criteria);
|
|
115
104
|
if (target)
|
|
116
|
-
await
|
|
105
|
+
await storage.delete(target.id);
|
|
117
106
|
},
|
|
118
107
|
deleteMany: async ({ model, where }) => {
|
|
119
|
-
const
|
|
108
|
+
const storage = storageOf(storageMap, model);
|
|
120
109
|
const criteria = whereToCriteria(where);
|
|
121
|
-
const targets = await
|
|
110
|
+
const targets = await storage.findAllBy(criteria);
|
|
122
111
|
for (const target of targets)
|
|
123
|
-
await
|
|
112
|
+
await storage.delete(target.id);
|
|
124
113
|
return targets.length;
|
|
125
114
|
},
|
|
126
115
|
}),
|
|
127
116
|
});
|
|
128
117
|
}
|
|
129
118
|
/**
|
|
130
|
-
* Augmented
|
|
131
|
-
* but
|
|
119
|
+
* Augmented Storage shape — the core interface doesn't expose findBy/findAllBy
|
|
120
|
+
* but SqlStorage (the only impl today) does. Cast locally to use them.
|
|
132
121
|
*/
|
|
133
122
|
/**
|
|
134
|
-
*
|
|
123
|
+
* Storage.findAllBy doesn't expose pagination/sort, so we apply them in JS
|
|
135
124
|
* after fetching the eq-filtered rows. Fine for auth volumes (orgs/sessions/accounts).
|
|
136
125
|
*/
|
|
137
126
|
function applyClientSidePagination(rows, sortBy, offset, limit) {
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAU5D
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAU5D,gCAAgC;AAChC,SAAS,eAAe,CAAC,KAA8B;IACrD,MAAM,QAAQ,GAA4B,EAAE,CAAC;IAC7C,KAAK,MAAM,MAAM,IAAI,KAAK,EAAE,CAAC;QAC3B,IAAI,MAAM,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACb,8BAA8B,MAAM,CAAC,QAAQ,iCAAiC,MAAM,CAAC,KAAK,KAAK;gBAC/F,6CAA6C,CAC9C,CAAC;QACJ,CAAC;QACD,IAAI,MAAM,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,2DAA2D,MAAM,CAAC,KAAK,KAAK,CAAC,CAAC;QAChG,CAAC;QACD,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;IACxC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,SAAS,CAAC,UAAsB,EAAE,KAAa;IACtD,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACtC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,mCAAmC,KAAK,KAAK;YAC7C,iBAAiB,CAAC,GAAG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AAC,CAAC;YACnC,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE,IAAI,IAAI;gBAAE,OAAO,CAAC,CAAC;YACvC,IAAI,EAAE,IAAI,IAAI;gBAAE,OAAO,CAAC,CAAC,CAAC;YAC1B,IAAI,EAAE,IAAI,IAAI;gBAAE,OAAO,CAAC,CAAC;YACzB,MAAM,GAAG,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3C,OAAO,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC;IACD,IAAI,MAAM,KAAK,SAAS;QAAE,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACxD,IAAI,KAAK,KAAK,SAAS;QAAE,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACzD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/entities.d.ts
CHANGED
|
@@ -8,13 +8,7 @@ declare const AuthUser_base: import("@fougere/schema").SchemaConstructor<{
|
|
|
8
8
|
createdAt: import("@fougere/schema").Field<Date>;
|
|
9
9
|
updatedAt: import("@fougere/schema").Field<Date>;
|
|
10
10
|
}>;
|
|
11
|
-
/**
|
|
12
|
-
* Default User entity — shipped as a fallback. Apps should declare their own
|
|
13
|
-
* User entity in a frond and pass it via `auth.user` (with extra fields like roles).
|
|
14
|
-
*
|
|
15
|
-
* Field shape matches better-auth's expectations: name/email/emailVerified/image
|
|
16
|
-
* + standard timestamps.
|
|
17
|
-
*/
|
|
11
|
+
/** Default User entity — shipped as a fallback. */
|
|
18
12
|
export declare class AuthUser extends AuthUser_base {
|
|
19
13
|
}
|
|
20
14
|
export declare function authEntities(User: SchemaView): {
|
package/dist/entities.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6D,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;;;;;;;;;;AAE7G
|
|
1
|
+
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6D,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;;;;;;;;;;AAE7G,mDAAmD;AACnD,qBAAa,QAAS,SAAQ,aAQ5B;CAAG;AAKL,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG;IAC9C,WAAW,EAAE,UAAU,CAAC;IACxB,WAAW,EAAE,UAAU,CAAC;CACzB,CAuCA;;;;;;;;;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,qBAOpC;CAAG"}
|
package/dist/entities.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { entity, primary, text, bool, date, created, ref, optional } from '@fougere/schema';
|
|
2
|
-
/**
|
|
3
|
-
* Default User entity — shipped as a fallback. Apps should declare their own
|
|
4
|
-
* User entity in a frond and pass it via `auth.user` (with extra fields like roles).
|
|
5
|
-
*
|
|
6
|
-
* Field shape matches better-auth's expectations: name/email/emailVerified/image
|
|
7
|
-
* + standard timestamps.
|
|
8
|
-
*/
|
|
2
|
+
/** Default User entity — shipped as a fallback. */
|
|
9
3
|
export class AuthUser extends entity({
|
|
10
4
|
id: primary(),
|
|
11
5
|
name: text(),
|
package/dist/entities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entities.js","sourceRoot":"","sources":["../src/entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAm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QAAQ,CAAC,IAAI,EAAE,CAAC;QAC9B,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QACzB,oBAAoB,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtC,qBAAqB,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QACvC,KAAK,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QACvB,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC1B,SAAS,EAAE,OAAO,EAAE;QACpB,SAAS,EAAE,OAAO,EAAE;KACrB,CAAC;KAAG;IAEL,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,MAAM,CAAC;IAC3C,EAAE,EAAE,OAAO,EAAE;IACb,UAAU,EAAE,IAAI,EAAE;IAClB,KAAK,EAAE,IAAI,EAAE;IACb,SAAS,EAAE,IAAI,EAAE;IACjB,SAAS,EAAE,OAAO,EAAE;IACpB,SAAS,EAAE,OAAO,EAAE;CACrB,CAAC;CAAG"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,14 +3,7 @@ import type { SchemaView } from '@fougere/schema';
|
|
|
3
3
|
import { type FougereProviders } from './translate.js';
|
|
4
4
|
export { AuthUser, AuthVerification, authEntities } from './entities.js';
|
|
5
5
|
export type { FougereProviders, OIDCProviderConfig } from './translate.js';
|
|
6
|
-
/**
|
|
7
|
-
* Options accepted by the betterAuth() factory in fougere.config.ts.
|
|
8
|
-
*
|
|
9
|
-
* `user` should come from the app's own frond (roles, extra columns, its own
|
|
10
|
-
* table — Session/Account are built against it, see `authEntities`). Omitting
|
|
11
|
-
* it falls back to the package's `AuthUser`. Other entities default to the
|
|
12
|
-
* shapes shipped by this package and can be overridden too.
|
|
13
|
-
*/
|
|
6
|
+
/** Options accepted by the betterAuth() factory in fougere.config.ts. */
|
|
14
7
|
export interface BetterAuthOptions {
|
|
15
8
|
user?: SchemaView;
|
|
16
9
|
secret: string;
|
|
@@ -23,17 +16,6 @@ export interface BetterAuthOptions {
|
|
|
23
16
|
account?: SchemaView;
|
|
24
17
|
verification?: SchemaView;
|
|
25
18
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Factory used in fougere.config.ts:
|
|
28
|
-
*
|
|
29
|
-
* ```ts
|
|
30
|
-
* export default defineFougere({
|
|
31
|
-
* auth: betterAuth({ user: User, secret, providers: {...} }),
|
|
32
|
-
* });
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* Returns a lazy AuthConfig — the better-auth engine is only constructed when
|
|
36
|
-
* the core calls `create(ctx)` at boot, with the resolved db + ormFactory.
|
|
37
|
-
*/
|
|
19
|
+
/** Factory used in fougere.config.ts. */
|
|
38
20
|
export declare function betterAuth(opts: BetterAuthOptions): AuthConfig;
|
|
39
21
|
//# 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":"AAEA,OAAO,KAAK,EAAE,UAAU,EAA4B,MAAM,eAAe,CAAC;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACzE,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAE3E
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAA4B,MAAM,eAAe,CAAC;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACzE,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAE3E,yEAAyE;AACzE,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,YAAY,CAAC,EAAE,UAAU,CAAC;CAC3B;AAED,yCAAyC;AACzC,wBAAgB,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,UAAU,CAmD9D"}
|
package/dist/index.js
CHANGED
|
@@ -4,18 +4,7 @@ import { AuthVerification, AuthUser, authEntities } from './entities.js';
|
|
|
4
4
|
import { fougereAdapter } from './adapter.js';
|
|
5
5
|
import { translateCredential, translateSocial, translatePlugins, } from './translate.js';
|
|
6
6
|
export { AuthUser, AuthVerification, authEntities } from './entities.js';
|
|
7
|
-
/**
|
|
8
|
-
* Factory used in fougere.config.ts:
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* export default defineFougere({
|
|
12
|
-
* auth: betterAuth({ user: User, secret, providers: {...} }),
|
|
13
|
-
* });
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* Returns a lazy AuthConfig — the better-auth engine is only constructed when
|
|
17
|
-
* the core calls `create(ctx)` at boot, with the resolved db + ormFactory.
|
|
18
|
-
*/
|
|
7
|
+
/** Factory used in fougere.config.ts. */
|
|
19
8
|
export function betterAuth(opts) {
|
|
20
9
|
const userSchema = opts.user ?? AuthUser;
|
|
21
10
|
const { AuthSession, AuthAccount } = authEntities(userSchema);
|
|
@@ -31,15 +20,15 @@ export function betterAuth(opts) {
|
|
|
31
20
|
account: accountSchema,
|
|
32
21
|
verification: verificationSchema,
|
|
33
22
|
},
|
|
34
|
-
create({
|
|
35
|
-
const
|
|
36
|
-
['user',
|
|
37
|
-
['session',
|
|
38
|
-
['account',
|
|
39
|
-
['verification',
|
|
23
|
+
create({ storageFactory }) {
|
|
24
|
+
const storageMap = new Map([
|
|
25
|
+
['user', storageFactory(userSchema, 'user')],
|
|
26
|
+
['session', storageFactory(sessionSchema, 'session')],
|
|
27
|
+
['account', storageFactory(accountSchema, 'account')],
|
|
28
|
+
['verification', storageFactory(verificationSchema, 'verification')],
|
|
40
29
|
]);
|
|
41
30
|
const engine = betterAuthLib({
|
|
42
|
-
database: fougereAdapter(
|
|
31
|
+
database: fougereAdapter(storageMap),
|
|
43
32
|
secret: opts.secret,
|
|
44
33
|
baseURL: opts.baseUrl,
|
|
45
34
|
basePath,
|
|
@@ -57,7 +46,7 @@ export function betterAuth(opts) {
|
|
|
57
46
|
account: accountSchema,
|
|
58
47
|
verification: verificationSchema,
|
|
59
48
|
},
|
|
60
|
-
|
|
49
|
+
storages: Object.fromEntries(storageMap),
|
|
61
50
|
handler: engine.handler,
|
|
62
51
|
api: engine.api,
|
|
63
52
|
basePath,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot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auth';
|
|
2
|
-
/**
|
|
3
|
-
* Fougere-side provider declaration. Mirrors what users write in fougere.config.ts.
|
|
4
|
-
*
|
|
5
|
-
* - `credential`: email + password (better-auth's emailAndPassword)
|
|
6
|
-
* - Standard OAuth keys (google, github, ...): become socialProviders
|
|
7
|
-
* - `oidc`: dictionary of OIDC providers, become genericOAuth plugin entries
|
|
8
|
-
*/
|
|
2
|
+
/** Fougere-side provider declaration. */
|
|
9
3
|
export interface FougereProviders {
|
|
10
4
|
credential?: {
|
|
11
5
|
minPasswordLength?: number;
|
|
@@ -58,10 +52,6 @@ export interface OIDCProviderConfig {
|
|
|
58
52
|
}
|
|
59
53
|
export declare function translateCredential(providers?: FougereProviders): BetterAuthOptions['emailAndPassword'];
|
|
60
54
|
export declare function translateSocial(providers?: FougereProviders): BetterAuthOptions['socialProviders'];
|
|
61
|
-
/**
|
|
62
|
-
* Build the plugin list from Fougere provider config.
|
|
63
|
-
* Currently produces:
|
|
64
|
-
* - `genericOAuth` plugin when `providers.oidc` is set (one entry per declared OIDC provider).
|
|
65
|
-
*/
|
|
55
|
+
/** Build the plugin list from Fougere provider config. */
|
|
66
56
|
export declare function translatePlugins(providers?: FougereProviders): BetterAuthPlugin[];
|
|
67
57
|
//# sourceMappingURL=translate.d.ts.map
|
package/dist/translate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translate.d.ts","sourceRoot":"","sources":["../src/translate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEvE
|
|
1
|
+
{"version":3,"file":"translate.d.ts","sourceRoot":"","sources":["../src/translate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEvE,yCAAyC;AACzC,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE;QACX,iBAAiB,CAAC,EAAE,MAA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AC;IAClB,mEAAmE;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAID,wBAAgB,mBAAmB,CAAC,SAAS,CAAC,EAAE,gBAAgB,GAAG,iBAAiB,CAAC,kBAAkB,CAAC,CASvG;AAED,wBAAgB,eAAe,CAAC,SAAS,CAAC,EAAE,gBAAgB,GAAG,iBAAiB,CAAC,iBAAiB,CAAC,CAOlG;AAED,0DAA0D;AAC1D,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,gBAAgB,GAAG,gBAAgB,EAAE,CAejF"}
|
package/dist/translate.js
CHANGED
|
@@ -21,11 +21,7 @@ export function translateSocial(providers) {
|
|
|
21
21
|
}
|
|
22
22
|
return social;
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Build the plugin list from Fougere provider config.
|
|
26
|
-
* Currently produces:
|
|
27
|
-
* - `genericOAuth` plugin when `providers.oidc` is set (one entry per declared OIDC provider).
|
|
28
|
-
*/
|
|
24
|
+
/** Build the plugin list from Fougere provider config. */
|
|
29
25
|
export function translatePlugins(providers) {
|
|
30
26
|
const plugins = [];
|
|
31
27
|
if (providers?.oidc) {
|
package/dist/translate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translate.js","sourceRoot":"","sources":["../src/translate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"translate.js","sourceRoot":"","sources":["../src/translate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAgCnD,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC;AAE/F,MAAM,UAAU,mBAAmB,CAAC,SAA4B;IAC9D,MAAM,IAA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AS,CAAC;YACrD,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,YAAY,EAAE,IAAI,CAAC,YAAY;SAChC,CAAC,CAAC,CAAC;QACJ,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fougere/auth-better",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-alpha.0",
|
|
4
4
|
"description": "Fougere's auth — a translation layer onto better-auth.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fougere",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@paralleldrive/cuid2": "^3.3.0",
|
|
33
33
|
"better-auth": "^1.6.11",
|
|
34
|
-
"@fougere/core": "0.
|
|
35
|
-
"@fougere/schema": "0.
|
|
34
|
+
"@fougere/core": "0.7.0-alpha.0",
|
|
35
|
+
"@fougere/schema": "0.7.0-alpha.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"vitest": "^4.1.0",
|
|
39
|
-
"@fougere/adapter-sql": "0.
|
|
39
|
+
"@fougere/adapter-sql": "0.7.0-alpha.0"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
package/src/adapter.ts
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import { createAdapterFactory } from 'better-auth/adapters';
|
|
2
2
|
import type { CleanedWhere, CustomAdapter } from 'better-auth/adapters';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Storage } from '@fougere/core';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Map of better-auth model names ('user', 'session', 'account', ...)
|
|
7
|
-
* to Fougere
|
|
7
|
+
* to Fougere Storage instances. Built once at boot by create() in index.ts.
|
|
8
8
|
*/
|
|
9
|
-
export type
|
|
9
|
+
export type StorageMap = Map<string, Storage>;
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Where[] supported subset:
|
|
13
|
-
* - All clauses use 'eq' operator
|
|
14
|
-
* - Implicit AND between clauses (no OR connector)
|
|
15
|
-
* Anything else throws — extend EntityOrm or add an engine-level fallback when needed.
|
|
16
|
-
*/
|
|
11
|
+
/** Where[] supported subset. */
|
|
17
12
|
function whereToCriteria(where: readonly CleanedWhere[]): Record<string, unknown> {
|
|
18
13
|
const criteria: Record<string, unknown> = {};
|
|
19
14
|
for (const clause of where) {
|
|
@@ -31,26 +26,20 @@ function whereToCriteria(where: readonly CleanedWhere[]): Record<string, unknown
|
|
|
31
26
|
return criteria;
|
|
32
27
|
}
|
|
33
28
|
|
|
34
|
-
function
|
|
35
|
-
const
|
|
36
|
-
if (!
|
|
29
|
+
function storageOf(storageMap: StorageMap, model: string): Storage {
|
|
30
|
+
const storage = storageMap.get(model);
|
|
31
|
+
if (!storage) {
|
|
37
32
|
throw new Error(
|
|
38
33
|
`[fougereAdapter] Unknown model '${model}'. ` +
|
|
39
|
-
`Known models: ${[...
|
|
34
|
+
`Known models: ${[...storageMap.keys()].join(', ')}. ` +
|
|
40
35
|
`Plugins that ship their own schema need entities registered explicitly.`,
|
|
41
36
|
);
|
|
42
37
|
}
|
|
43
|
-
return
|
|
38
|
+
return storage;
|
|
44
39
|
}
|
|
45
40
|
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
-
*
|
|
49
|
-
* This closes the loop: the same `db` resolved by Fougere's bootstrap is the
|
|
50
|
-
* one EntityOrm writes to, and better-auth never touches the storage directly.
|
|
51
|
-
* If Fougere swaps Kysely for another backend, this adapter follows for free.
|
|
52
|
-
*/
|
|
53
|
-
export function fougereAdapter(ormMap: OrmMap) {
|
|
41
|
+
/** Better-auth adapter that routes every operation through Fougere Storage. */
|
|
42
|
+
export function fougereAdapter(storageMap: StorageMap) {
|
|
54
43
|
return createAdapterFactory({
|
|
55
44
|
config: {
|
|
56
45
|
adapterId: 'fougere',
|
|
@@ -58,25 +47,25 @@ export function fougereAdapter(ormMap: OrmMap) {
|
|
|
58
47
|
usePlural: false,
|
|
59
48
|
supportsArrays: false,
|
|
60
49
|
supportsJSON: false,
|
|
61
|
-
// The
|
|
50
|
+
// The storage converts both ways now (`schema-sql/src/values.ts`), so better-auth
|
|
62
51
|
// can hand over the Dates and booleans its own types declare.
|
|
63
52
|
supportsDates: true,
|
|
64
53
|
supportsBooleans: true,
|
|
65
54
|
},
|
|
66
55
|
adapter: (): CustomAdapter => ({
|
|
67
56
|
create: async ({ model, data }: { model: string; data: Record<string, unknown> }) => {
|
|
68
|
-
const
|
|
69
|
-
return (await
|
|
57
|
+
const storage = storageOf(storageMap, model);
|
|
58
|
+
return (await storage.create(data)) as never;
|
|
70
59
|
},
|
|
71
60
|
|
|
72
61
|
findOne: async ({ model, where }: { model: string; where: CleanedWhere[] }) => {
|
|
73
|
-
const
|
|
62
|
+
const storage = storageOf(storageMap, model);
|
|
74
63
|
const criteria = whereToCriteria(where);
|
|
75
64
|
if (Object.keys(criteria).length === 1 && 'id' in criteria) {
|
|
76
|
-
const found = await
|
|
65
|
+
const found = await storage.findById(criteria.id as string);
|
|
77
66
|
return (found ?? null) as never;
|
|
78
67
|
}
|
|
79
|
-
const found = await
|
|
68
|
+
const found = await storage.findBy(criteria);
|
|
80
69
|
return (found ?? null) as never;
|
|
81
70
|
},
|
|
82
71
|
|
|
@@ -93,13 +82,13 @@ export function fougereAdapter(ormMap: OrmMap) {
|
|
|
93
82
|
offset?: number;
|
|
94
83
|
sortBy?: { field: string; direction: 'asc' | 'desc' };
|
|
95
84
|
}) => {
|
|
96
|
-
const
|
|
85
|
+
const storage = storageOf(storageMap, model);
|
|
97
86
|
if (where && where.length > 0) {
|
|
98
87
|
const criteria = whereToCriteria(where);
|
|
99
|
-
const rows = await
|
|
88
|
+
const rows = await storage.findAllBy(criteria);
|
|
100
89
|
return applyClientSidePagination(rows, sortBy, offset, limit) as never;
|
|
101
90
|
}
|
|
102
|
-
const rows = await
|
|
91
|
+
const rows = await storage.list({
|
|
103
92
|
limit,
|
|
104
93
|
offset,
|
|
105
94
|
orderBy: sortBy?.field,
|
|
@@ -109,48 +98,48 @@ export function fougereAdapter(ormMap: OrmMap) {
|
|
|
109
98
|
},
|
|
110
99
|
|
|
111
100
|
count: async ({ model, where }: { model: string; where?: CleanedWhere[] }) => {
|
|
112
|
-
const
|
|
101
|
+
const storage = storageOf(storageMap, model);
|
|
113
102
|
if (where && where.length > 0) {
|
|
114
103
|
const criteria = whereToCriteria(where);
|
|
115
|
-
const rows = await
|
|
104
|
+
const rows = await storage.findAllBy(criteria);
|
|
116
105
|
return rows.length;
|
|
117
106
|
}
|
|
118
|
-
const rows = await
|
|
107
|
+
const rows = await storage.list({ count: true });
|
|
119
108
|
return rows.total ?? rows.length;
|
|
120
109
|
},
|
|
121
110
|
|
|
122
111
|
update: async <T>({ model, where, update }: { model: string; where: CleanedWhere[]; update: T }): Promise<T | null> => {
|
|
123
|
-
const
|
|
112
|
+
const storage = storageOf(storageMap, model);
|
|
124
113
|
const criteria = whereToCriteria(where);
|
|
125
114
|
const target = 'id' in criteria
|
|
126
|
-
? await
|
|
127
|
-
: await
|
|
115
|
+
? await storage.findById(criteria.id as string)
|
|
116
|
+
: await storage.findBy(criteria);
|
|
128
117
|
if (!target) return null;
|
|
129
|
-
return (await
|
|
118
|
+
return (await storage.update(target.id as string, update as Partial<Record<string, unknown>>)) as T;
|
|
130
119
|
},
|
|
131
120
|
|
|
132
121
|
updateMany: async ({ model, where, update }: { model: string; where: CleanedWhere[]; update: Record<string, unknown> }) => {
|
|
133
|
-
const
|
|
122
|
+
const storage = storageOf(storageMap, model);
|
|
134
123
|
const criteria = whereToCriteria(where);
|
|
135
|
-
const targets = await
|
|
136
|
-
for (const target of targets) await
|
|
124
|
+
const targets = await storage.findAllBy(criteria);
|
|
125
|
+
for (const target of targets) await storage.update(target.id as string, update);
|
|
137
126
|
return targets.length;
|
|
138
127
|
},
|
|
139
128
|
|
|
140
129
|
delete: async ({ model, where }: { model: string; where: CleanedWhere[] }) => {
|
|
141
|
-
const
|
|
130
|
+
const storage = storageOf(storageMap, model);
|
|
142
131
|
const criteria = whereToCriteria(where);
|
|
143
132
|
const target = 'id' in criteria
|
|
144
|
-
? await
|
|
145
|
-
: await
|
|
146
|
-
if (target) await
|
|
133
|
+
? await storage.findById(criteria.id as string)
|
|
134
|
+
: await storage.findBy(criteria);
|
|
135
|
+
if (target) await storage.delete(target.id as string);
|
|
147
136
|
},
|
|
148
137
|
|
|
149
138
|
deleteMany: async ({ model, where }: { model: string; where: CleanedWhere[] }) => {
|
|
150
|
-
const
|
|
139
|
+
const storage = storageOf(storageMap, model);
|
|
151
140
|
const criteria = whereToCriteria(where);
|
|
152
|
-
const targets = await
|
|
153
|
-
for (const target of targets) await
|
|
141
|
+
const targets = await storage.findAllBy(criteria);
|
|
142
|
+
for (const target of targets) await storage.delete(target.id as string);
|
|
154
143
|
return targets.length;
|
|
155
144
|
},
|
|
156
145
|
}),
|
|
@@ -158,11 +147,11 @@ export function fougereAdapter(ormMap: OrmMap) {
|
|
|
158
147
|
}
|
|
159
148
|
|
|
160
149
|
/**
|
|
161
|
-
* Augmented
|
|
162
|
-
* but
|
|
150
|
+
* Augmented Storage shape — the core interface doesn't expose findBy/findAllBy
|
|
151
|
+
* but SqlStorage (the only impl today) does. Cast locally to use them.
|
|
163
152
|
*/
|
|
164
153
|
/**
|
|
165
|
-
*
|
|
154
|
+
* Storage.findAllBy doesn't expose pagination/sort, so we apply them in JS
|
|
166
155
|
* after fetching the eq-filtered rows. Fine for auth volumes (orgs/sessions/accounts).
|
|
167
156
|
*/
|
|
168
157
|
function applyClientSidePagination(
|
package/src/entities.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { entity, primary, text, bool, date, created, ref, optional, type SchemaView } from '@fougere/schema';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Default User entity — shipped as a fallback. Apps should declare their own
|
|
5
|
-
* User entity in a frond and pass it via `auth.user` (with extra fields like roles).
|
|
6
|
-
*
|
|
7
|
-
* Field shape matches better-auth's expectations: name/email/emailVerified/image
|
|
8
|
-
* + standard timestamps.
|
|
9
|
-
*/
|
|
3
|
+
/** Default User entity — shipped as a fallback. */
|
|
10
4
|
export class AuthUser extends entity({
|
|
11
5
|
id: primary(),
|
|
12
6
|
name: text(),
|
|
@@ -17,23 +11,7 @@ export class AuthUser extends entity({
|
|
|
17
11
|
updatedAt: created(),
|
|
18
12
|
}) {}
|
|
19
13
|
|
|
20
|
-
/**
|
|
21
|
-
* A `ref()` target is fixed at field-declaration time. Session and Account can't
|
|
22
|
-
* be static classes built once against this package's `AuthUser` — that would
|
|
23
|
-
* leave `userId` pointing at the wrong table whenever an app supplies its own
|
|
24
|
-
* User (`opts.user` in `betterAuth()`). `authEntities(User)` builds them fresh
|
|
25
|
-
* against whichever schema was actually resolved (the app's, or `AuthUser` as
|
|
26
|
-
* fallback), called from `betterAuth()` once `User` is known.
|
|
27
|
-
*
|
|
28
|
-
* `ref()` wants a live class — a construct signature plus `.name`, which
|
|
29
|
-
* `@fougere/adapter-sql`'s FK naming reads off the target — narrower than the
|
|
30
|
-
* `SchemaView` interface (`getFields()` only) this package's public options
|
|
31
|
-
* take, since `opts.user` may be any app's entity and `SchemaView` is the
|
|
32
|
-
* shape-only contract used to stay decoupled from a specific one. Every real
|
|
33
|
-
* entity satisfies both; the cast below only crosses that type-level gap, the
|
|
34
|
-
* same bridge `@fougere/schema` uses internally in `Bundle.toSchemas`
|
|
35
|
-
* (`schema as unknown as EntityConstructor`).
|
|
36
|
-
*/
|
|
14
|
+
/** A `ref()` target is fixed at field-declaration time. */
|
|
37
15
|
type LiveEntity = abstract new (...args: any[]) => unknown;
|
|
38
16
|
|
|
39
17
|
export function authEntities(User: SchemaView): {
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { createId } from '@paralleldrive/cuid2';
|
|
|
3
3
|
import type { AuthConfig, AuthContext, AuthRuntime } from '@fougere/core';
|
|
4
4
|
import type { SchemaView } from '@fougere/schema';
|
|
5
5
|
import { AuthVerification, AuthUser, authEntities } from './entities.js';
|
|
6
|
-
import { fougereAdapter, type
|
|
6
|
+
import { fougereAdapter, type StorageMap } from './adapter.js';
|
|
7
7
|
import {
|
|
8
8
|
translateCredential,
|
|
9
9
|
translateSocial,
|
|
@@ -14,14 +14,7 @@ import {
|
|
|
14
14
|
export { AuthUser, AuthVerification, authEntities } from './entities.js';
|
|
15
15
|
export type { FougereProviders, OIDCProviderConfig } from './translate.js';
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* Options accepted by the betterAuth() factory in fougere.config.ts.
|
|
19
|
-
*
|
|
20
|
-
* `user` should come from the app's own frond (roles, extra columns, its own
|
|
21
|
-
* table — Session/Account are built against it, see `authEntities`). Omitting
|
|
22
|
-
* it falls back to the package's `AuthUser`. Other entities default to the
|
|
23
|
-
* shapes shipped by this package and can be overridden too.
|
|
24
|
-
*/
|
|
17
|
+
/** Options accepted by the betterAuth() factory in fougere.config.ts. */
|
|
25
18
|
export interface BetterAuthOptions {
|
|
26
19
|
user?: SchemaView;
|
|
27
20
|
secret: string;
|
|
@@ -35,18 +28,7 @@ export interface BetterAuthOptions {
|
|
|
35
28
|
verification?: SchemaView;
|
|
36
29
|
}
|
|
37
30
|
|
|
38
|
-
/**
|
|
39
|
-
* Factory used in fougere.config.ts:
|
|
40
|
-
*
|
|
41
|
-
* ```ts
|
|
42
|
-
* export default defineFougere({
|
|
43
|
-
* auth: betterAuth({ user: User, secret, providers: {...} }),
|
|
44
|
-
* });
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* Returns a lazy AuthConfig — the better-auth engine is only constructed when
|
|
48
|
-
* the core calls `create(ctx)` at boot, with the resolved db + ormFactory.
|
|
49
|
-
*/
|
|
31
|
+
/** Factory used in fougere.config.ts. */
|
|
50
32
|
export function betterAuth(opts: BetterAuthOptions): AuthConfig {
|
|
51
33
|
const userSchema = opts.user ?? AuthUser;
|
|
52
34
|
const { AuthSession, AuthAccount } = authEntities(userSchema);
|
|
@@ -63,16 +45,16 @@ export function betterAuth(opts: BetterAuthOptions): AuthConfig {
|
|
|
63
45
|
account: accountSchema,
|
|
64
46
|
verification: verificationSchema,
|
|
65
47
|
},
|
|
66
|
-
create({
|
|
67
|
-
const
|
|
68
|
-
['user',
|
|
69
|
-
['session',
|
|
70
|
-
['account',
|
|
71
|
-
['verification',
|
|
48
|
+
create({ storageFactory }: AuthContext): AuthRuntime {
|
|
49
|
+
const storageMap: StorageMap = new Map([
|
|
50
|
+
['user', storageFactory(userSchema, 'user')],
|
|
51
|
+
['session', storageFactory(sessionSchema, 'session')],
|
|
52
|
+
['account', storageFactory(accountSchema, 'account')],
|
|
53
|
+
['verification', storageFactory(verificationSchema, 'verification')],
|
|
72
54
|
]);
|
|
73
55
|
|
|
74
56
|
const engine = betterAuthLib({
|
|
75
|
-
database: fougereAdapter(
|
|
57
|
+
database: fougereAdapter(storageMap),
|
|
76
58
|
secret: opts.secret,
|
|
77
59
|
baseURL: opts.baseUrl,
|
|
78
60
|
basePath,
|
|
@@ -91,7 +73,7 @@ export function betterAuth(opts: BetterAuthOptions): AuthConfig {
|
|
|
91
73
|
account: accountSchema,
|
|
92
74
|
verification: verificationSchema,
|
|
93
75
|
},
|
|
94
|
-
|
|
76
|
+
storages: Object.fromEntries(storageMap),
|
|
95
77
|
handler: engine.handler,
|
|
96
78
|
api: engine.api as Record<string, unknown>,
|
|
97
79
|
basePath,
|
package/src/translate.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { genericOAuth } from 'better-auth/plugins';
|
|
2
2
|
import type { BetterAuthOptions, BetterAuthPlugin } from 'better-auth';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Fougere-side provider declaration. Mirrors what users write in fougere.config.ts.
|
|
6
|
-
*
|
|
7
|
-
* - `credential`: email + password (better-auth's emailAndPassword)
|
|
8
|
-
* - Standard OAuth keys (google, github, ...): become socialProviders
|
|
9
|
-
* - `oidc`: dictionary of OIDC providers, become genericOAuth plugin entries
|
|
10
|
-
*/
|
|
4
|
+
/** Fougere-side provider declaration. */
|
|
11
5
|
export interface FougereProviders {
|
|
12
6
|
credential?: {
|
|
13
7
|
minPasswordLength?: number;
|
|
@@ -58,11 +52,7 @@ export function translateSocial(providers?: FougereProviders): BetterAuthOptions
|
|
|
58
52
|
return social as BetterAuthOptions['socialProviders'];
|
|
59
53
|
}
|
|
60
54
|
|
|
61
|
-
/**
|
|
62
|
-
* Build the plugin list from Fougere provider config.
|
|
63
|
-
* Currently produces:
|
|
64
|
-
* - `genericOAuth` plugin when `providers.oidc` is set (one entry per declared OIDC provider).
|
|
65
|
-
*/
|
|
55
|
+
/** Build the plugin list from Fougere provider config. */
|
|
66
56
|
export function translatePlugins(providers?: FougereProviders): BetterAuthPlugin[] {
|
|
67
57
|
const plugins: BetterAuthPlugin[] = [];
|
|
68
58
|
if (providers?.oidc) {
|