@fougere/auth-better 0.12.4-alpha.0 → 0.12.5-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 CHANGED
@@ -2,8 +2,9 @@
2
2
  > Fougere's auth
3
3
  A translation layer onto [better-auth](https://better-auth.com): its writes go through
4
4
  Fougere's storage, and the application's `User` stays its own — Session and Account are
5
- built against it. `betterAuth()` is an extension: it brings the frond those rows live in, and
6
- registers the runtime under `AUTH` once the app exists.
5
+ built against it. `betterAuth()` is a frond, `fronds: { auth: betterAuth({ … }) }`: it holds
6
+ those rows, and carries the extension that registers the runtime under `AUTH` wherever the
7
+ frond is served.
7
8
 
8
9
  ## Installation
9
10
  ```bash
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { type Extension } from '@fougere/core';
1
+ import { type FrondDescriptor } from '@fougere/core';
2
2
  import { type SchemaView } from '@fougere/schema';
3
3
  import { type FougereProviders } from './FougereProviders.js';
4
4
  export { AuthUser } from './entity/AuthUser.js';
5
- /** Options accepted by the betterAuth() factory in fougere.config.ts. */
5
+ /** What `fronds: { '@fougere/auth-better': { … } }` hands the factory in fougere.config.ts. */
6
6
  export interface BetterAuthOptions {
7
7
  user?: SchemaView;
8
8
  secret: string;
@@ -16,8 +16,12 @@ export interface BetterAuthOptions {
16
16
  verification?: SchemaView;
17
17
  }
18
18
  /**
19
- * The auth provider, as an extension: it brings the frond its rows live in — the user too, when
20
- * the app names none — and registers the runtime under `AUTH` once the app exists.
19
+ * The auth provider, as a frond: its rows — the user too, when the app names none — and the
20
+ * extension that rises where it is served, declaring what a signed-in call carries and
21
+ * registering the runtime under `AUTH`. Placed like any frond: a process whose `only:` leaves it
22
+ * out starts no engine and migrates no session table. The session travels without its
23
+ * `token`: a process trusts the one that called it, never the cookie of whoever is behind it.
21
24
  */
22
- export declare function betterAuth(opts: BetterAuthOptions): Extension;
25
+ export declare function betterAuth(opts: BetterAuthOptions): FrondDescriptor;
26
+ export default betterAuth;
23
27
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2C,KAAK,SAAS,EAAgB,MAAM,eAAe,CAAC;AACtG,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAK9D,OAAO,EAA0D,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEtH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,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;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,SAAS,CAkC7D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2C,KAAK,eAAe,EAAgB,MAAM,eAAe,CAAC;AAC5G,OAAO,EAAiC,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAKjF,OAAO,EAA0D,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEtH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,+FAA+F;AAC/F,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;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,eAAe,CAqCnE;eAEc,UAAU"}
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { betterAuth as betterAuthLib } from 'better-auth';
2
2
  import { createId } from '@paralleldrive/cuid2';
3
3
  import { AUTH, frond } from '@fougere/core';
4
- import { lowerFirst } from '@fougere/schema';
4
+ import { json, lowerFirst } from '@fougere/schema';
5
5
  import { AuthUser } from './entity/AuthUser.js';
6
6
  import { AuthVerification } from './entity/AuthVerification.js';
7
7
  import { authEntities } from './entity/authEntities.js';
@@ -9,8 +9,11 @@ import { fougereAdapter } from './adapter.js';
9
9
  import { translateCredential, translatePlugins, translateSocial } from './FougereProviders.js';
10
10
  export { AuthUser } from './entity/AuthUser.js';
11
11
  /**
12
- * The auth provider, as an extension: it brings the frond its rows live in — the user too, when
13
- * the app names none — and registers the runtime under `AUTH` once the app exists.
12
+ * The auth provider, as a frond: its rows — the user too, when the app names none — and the
13
+ * extension that rises where it is served, declaring what a signed-in call carries and
14
+ * registering the runtime under `AUTH`. Placed like any frond: a process whose `only:` leaves it
15
+ * out starts no engine and migrates no session table. The session travels without its
16
+ * `token`: a process trusts the one that called it, never the cookie of whoever is behind it.
14
17
  */
15
18
  export function betterAuth(opts) {
16
19
  const user = opts.user ?? AuthUser;
@@ -24,27 +27,31 @@ export function betterAuth(opts) {
24
27
  const brought = Object.values(models).filter((schema) => schema !== opts.user);
25
28
  const providers = opts.providers ?? {};
26
29
  const basePath = opts.basePath ?? '/auth';
27
- return {
28
- name: 'auth',
29
- fronds: [frond('auth', { entities: brought })],
30
- up(app) {
31
- const engine = betterAuthLib({
32
- database: fougereAdapter(storagesOf(app, models)),
33
- secret: opts.secret,
34
- baseURL: opts.baseUrl,
35
- basePath,
36
- trustedOrigins: opts.trustedOrigins,
37
- advanced: { database: { generateId: () => createId() } },
38
- session: opts.sessionTtl ? { expiresIn: opts.sessionTtl / 1000 } : undefined,
39
- emailAndPassword: translateCredential(providers),
40
- socialProviders: translateSocial(providers),
41
- plugins: translatePlugins(providers),
42
- });
43
- const runtime = { handler: engine.handler, api: engine.api, basePath };
44
- app.container.registerValue(AUTH, runtime);
45
- },
46
- };
30
+ return frond('auth', {
31
+ entities: brought,
32
+ extensions: [{
33
+ name: 'auth',
34
+ state: { user: json(user), session: json(models.session.omit('token')) },
35
+ up(app) {
36
+ const engine = betterAuthLib({
37
+ database: fougereAdapter(storagesOf(app, models)),
38
+ secret: opts.secret,
39
+ baseURL: opts.baseUrl,
40
+ basePath,
41
+ trustedOrigins: opts.trustedOrigins,
42
+ advanced: { database: { generateId: () => createId() } },
43
+ session: opts.sessionTtl ? { expiresIn: opts.sessionTtl / 1000 } : undefined,
44
+ emailAndPassword: translateCredential(providers),
45
+ socialProviders: translateSocial(providers),
46
+ plugins: translatePlugins(providers),
47
+ });
48
+ const runtime = { handler: engine.handler, api: engine.api, basePath };
49
+ app.container.registerValue(AUTH, runtime);
50
+ },
51
+ }],
52
+ });
47
53
  }
54
+ export default betterAuth;
48
55
  function storagesOf(app, models) {
49
56
  return new Map(Object.entries(models).map(([model, schema]) => {
50
57
  const entity = lowerFirst(schema.name);
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,C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MAAM,OAAO,GAAgB,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,GAA8B,EAAE,QAAQ,EAAE,CAAC;oBAE/G,GAAG,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBAC7C,CAAC;aACF,CAAC;KACH,CAAC,CAAC;AACL,CAAC;AAED,eAAe,UAAU,CAAC;AAE1B,SAAS,UAAU,CAAC,GAAQ,EAAE,MAAkC;IAC9D,OAAO,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,EAAE;QAC5D,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACvC,MAAM,OAAO,GAAwB,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAC5D,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,0CAA0C,MAAM,UAAU,KAAK,sBAAsB,CAAC,CAAC;QAErH,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC,CAAC;AACN,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fougere/auth-better",
3
- "version": "0.12.4-alpha.0",
3
+ "version": "0.12.5-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.12.4-alpha.0",
35
- "@fougere/schema": "0.12.4-alpha.0"
34
+ "@fougere/core": "0.12.5-alpha.0",
35
+ "@fougere/schema": "0.12.5-alpha.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "vitest": "^4.1.0",
39
- "@fougere/adapter-sql": "0.12.4-alpha.0"
39
+ "@fougere/adapter-sql": "0.12.5-alpha.0"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public"
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { betterAuth as betterAuthLib } from 'better-auth';
2
2
  import { createId } from '@paralleldrive/cuid2';
3
- import { AUTH, frond, type App, type AuthRuntime, type Extension, type Storage } from '@fougere/core';
4
- import { lowerFirst, type SchemaView } from '@fougere/schema';
3
+ import { AUTH, frond, type App, type AuthRuntime, type FrondDescriptor, type Storage } from '@fougere/core';
4
+ import { json, lowerFirst, type Schema, type SchemaView } from '@fougere/schema';
5
5
  import { AuthUser } from './entity/AuthUser.js';
6
6
  import { AuthVerification } from './entity/AuthVerification.js';
7
7
  import { authEntities } from './entity/authEntities.js';
@@ -10,7 +10,7 @@ import { translateCredential, translatePlugins, translateSocial, type FougerePro
10
10
 
11
11
  export { AuthUser } from './entity/AuthUser.js';
12
12
 
13
- /** Options accepted by the betterAuth() factory in fougere.config.ts. */
13
+ /** What `fronds: { '@fougere/auth-better': { … } }` hands the factory in fougere.config.ts. */
14
14
  export interface BetterAuthOptions {
15
15
  user?: SchemaView;
16
16
  secret: string;
@@ -25,10 +25,13 @@ export interface BetterAuthOptions {
25
25
  }
26
26
 
27
27
  /**
28
- * The auth provider, as an extension: it brings the frond its rows live in — the user too, when
29
- * the app names none — and registers the runtime under `AUTH` once the app exists.
28
+ * The auth provider, as a frond: its rows — the user too, when the app names none — and the
29
+ * extension that rises where it is served, declaring what a signed-in call carries and
30
+ * registering the runtime under `AUTH`. Placed like any frond: a process whose `only:` leaves it
31
+ * out starts no engine and migrates no session table. The session travels without its
32
+ * `token`: a process trusts the one that called it, never the cookie of whoever is behind it.
30
33
  */
31
- export function betterAuth(opts: BetterAuthOptions): Extension {
34
+ export function betterAuth(opts: BetterAuthOptions): FrondDescriptor {
32
35
  const user = opts.user ?? AuthUser;
33
36
  const { AuthSession, AuthAccount } = authEntities(user);
34
37
  const models: Record<string, SchemaView> = {
@@ -41,29 +44,34 @@ export function betterAuth(opts: BetterAuthOptions): Extension {
41
44
  const providers = opts.providers ?? {};
42
45
  const basePath = opts.basePath ?? '/auth';
43
46
 
44
- return {
45
- name: 'auth',
46
- fronds: [frond('auth', { entities: brought })],
47
- up(app) {
48
- const engine = betterAuthLib({
49
- database: fougereAdapter(storagesOf(app, models)),
50
- secret: opts.secret,
51
- baseURL: opts.baseUrl,
52
- basePath,
53
- trustedOrigins: opts.trustedOrigins,
54
- advanced: { database: { generateId: () => createId() } },
55
- session: opts.sessionTtl ? { expiresIn: opts.sessionTtl / 1000 } : undefined,
56
- emailAndPassword: translateCredential(providers),
57
- socialProviders: translateSocial(providers),
58
- plugins: translatePlugins(providers),
59
- });
60
- const runtime: AuthRuntime = { handler: engine.handler, api: engine.api as Record<string, unknown>, basePath };
47
+ return frond('auth', {
48
+ entities: brought,
49
+ extensions: [{
50
+ name: 'auth',
51
+ state: { user: json(user as typeof Schema), session: json((models.session as typeof Schema).omit('token')) },
52
+ up(app: App) {
53
+ const engine = betterAuthLib({
54
+ database: fougereAdapter(storagesOf(app, models)),
55
+ secret: opts.secret,
56
+ baseURL: opts.baseUrl,
57
+ basePath,
58
+ trustedOrigins: opts.trustedOrigins,
59
+ advanced: { database: { generateId: () => createId() } },
60
+ session: opts.sessionTtl ? { expiresIn: opts.sessionTtl / 1000 } : undefined,
61
+ emailAndPassword: translateCredential(providers),
62
+ socialProviders: translateSocial(providers),
63
+ plugins: translatePlugins(providers),
64
+ });
65
+ const runtime: AuthRuntime = { handler: engine.handler, api: engine.api as Record<string, unknown>, basePath };
61
66
 
62
- app.container.registerValue(AUTH, runtime);
63
- },
64
- };
67
+ app.container.registerValue(AUTH, runtime);
68
+ },
69
+ }],
70
+ });
65
71
  }
66
72
 
73
+ export default betterAuth;
74
+
67
75
  function storagesOf(app: App, models: Record<string, SchemaView>): StorageMap {
68
76
  return new Map(Object.entries(models).map(([model, schema]) => {
69
77
  const entity = lowerFirst(schema.name);