@lunora/auth 1.0.0-alpha.32 → 1.0.0-alpha.34
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/dist/adapter.d.mts +35 -35
- package/dist/adapter.d.ts +35 -35
- package/dist/index.d.mts +170 -169
- package/dist/index.d.ts +170 -169
- package/dist/middleware.d.mts +154 -154
- package/dist/middleware.d.ts +154 -154
- package/dist/packem_shared/create-auth.d-COcIS_KU.d.mts +128 -0
- package/dist/packem_shared/create-auth.d-COcIS_KU.d.ts +128 -0
- package/dist/schema.d.mts +39 -39
- package/dist/schema.d.ts +39 -39
- package/dist/sql-store.d.mts +28 -28
- package/dist/sql-store.d.ts +28 -28
- package/dist/store.d.mts +47 -47
- package/dist/store.d.ts +47 -47
- package/dist/turnstile-middleware.d.mts +55 -55
- package/dist/turnstile-middleware.d.ts +55 -55
- package/dist/turnstile.d.mts +42 -49
- package/dist/turnstile.d.ts +42 -49
- package/package.json +4 -4
- package/dist/packem_shared/create-auth.d-Mwhb4gSc.d.mts +0 -128
- package/dist/packem_shared/create-auth.d-Mwhb4gSc.d.ts +0 -128
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { betterAuth, BetterAuthOptions } from 'better-auth';
|
|
2
|
-
/**
|
|
3
|
-
* Lunora's options pass straight through to better-auth — the only thing we add
|
|
4
|
-
* is requiring `secret` up front so a misconfigured deployment fails loudly
|
|
5
|
-
* instead of at the first sign-in.
|
|
6
|
-
*
|
|
7
|
-
* For `database`, prefer `lunoraD1Adapter` (`database: lunoraD1Adapter(env.DB)`)
|
|
8
|
-
* over passing the raw `env.DB`. better-auth *does* accept a D1Database directly,
|
|
9
|
-
* but it then resolves its Kysely adapter via a runtime `await import(...)` inside
|
|
10
|
-
* `auth.$context` — and that import never settles under `@cloudflare/vite-plugin`'s
|
|
11
|
-
* worker runner, hanging every auth request in `pnpm dev`. The explicit adapter
|
|
12
|
-
* skips it, so dev and prod behave the same. (Raw `env.DB` is still correct for
|
|
13
|
-
* the migration-only instance — see `lunoraD1Adapter`'s note.)
|
|
14
|
-
*
|
|
15
|
-
* Session rotation / richer session policies are configured via the `session`
|
|
16
|
-
* field (a `SessionPolicy`); Lunora validates it for obviously-broken
|
|
17
|
-
* durations and forwards it verbatim to better-auth. See `sessionPresets`
|
|
18
|
-
* for ready-made rotation/expiry trade-offs.
|
|
19
|
-
*
|
|
20
|
-
* ## Serverless background tasks (Cloudflare Workers)
|
|
21
|
-
*
|
|
22
|
-
* better-auth runs some work *after* sending the response — most importantly the
|
|
23
|
-
* password-reset email, whose background send is what keeps reset responses
|
|
24
|
-
* constant-time (a timing-attack defence: the response doesn't reveal whether
|
|
25
|
-
* the account exists). On Cloudflare Workers a promise that isn't handed to
|
|
26
|
-
* `ctx.waitUntil` can be cancelled the moment the response returns, dropping
|
|
27
|
-
* that send and weakening the guarantee. Wire your request's `ctx.waitUntil`
|
|
28
|
-
* into better-auth's background handler so the work survives:
|
|
29
|
-
*
|
|
30
|
-
* ```ts
|
|
31
|
-
* // in your worker fetch handler, where `ctx: ExecutionContext` is in scope
|
|
32
|
-
* const auth = createAuth({
|
|
33
|
-
* secret: env.AUTH_SECRET,
|
|
34
|
-
* database: lunoraD1Adapter(env.DB),
|
|
35
|
-
* advanced: {
|
|
36
|
-
* backgroundTasks: { handler: (promise) => ctx.waitUntil(promise) },
|
|
37
|
-
* },
|
|
38
|
-
* });
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* (Lunora can't set this for you — `ctx.waitUntil` is per-request, but
|
|
42
|
-
* `createAuth` runs once at worker setup.)
|
|
43
|
-
*/
|
|
44
|
-
type LunoraAuthOptions = BetterAuthOptions;
|
|
45
|
-
/**
|
|
46
|
-
* The full better-auth instance: `auth.handler` accepts a `Request` and
|
|
47
|
-
* returns a `Response` (used by `handleAuthRequest`); `auth.api`
|
|
48
|
-
* exposes the typed endpoint surface for server-side calls (e.g.
|
|
49
|
-
* `auth.api.getSession({ headers })` inside a query/mutation).
|
|
50
|
-
*/
|
|
51
|
-
type LunoraAuth = ReturnType<typeof betterAuth>;
|
|
52
|
-
/**
|
|
53
|
-
* Resolve the caller's options into the exact shape `createAuth` hands to
|
|
54
|
-
* `betterAuth` — the hardened, default-filled options the running worker uses.
|
|
55
|
-
* Exported (and pure) so the migration path can compile the schema from the
|
|
56
|
-
* same resolved options: `compileMigrationsSql` routes through here, so the
|
|
57
|
-
* `rateLimit` table the worker's durable limiter writes to is included in the
|
|
58
|
-
* migration rather than silently omitted (it would be, if migrations saw the
|
|
59
|
-
* raw options while the worker ran the resolved ones).
|
|
60
|
-
*
|
|
61
|
-
* ## What it fills (each gated independently on caller silence)
|
|
62
|
-
*
|
|
63
|
-
* Secure-by-default cookies + secret-strength warning via {@link hardenAuthOptions},
|
|
64
|
-
* applied first so all hardening composes onto one options object.
|
|
65
|
-
*
|
|
66
|
-
* Rate limiting is ON by default for `/api/auth/*`.
|
|
67
|
-
*
|
|
68
|
-
* better-auth's own default is `rateLimit.enabled ?? isProduction`, and its
|
|
69
|
-
* `isProduction` is `"development" === "production"` resolved at
|
|
70
|
-
* module-load time. On Cloudflare Workers that check is unreliable: the
|
|
71
|
-
* runtime has no Node `process.env` (absent entirely without
|
|
72
|
-
* `nodejs_compat`, and even with it `NODE_ENV` is rarely `"production"` at
|
|
73
|
-
* request time). So better-auth would silently leave auth endpoints
|
|
74
|
-
* _unthrottled_ on a real deployment — the surprise we refuse to ship.
|
|
75
|
-
*
|
|
76
|
-
* We therefore default `enabled: true` whenever the caller hasn't made an
|
|
77
|
-
* explicit choice. We only fill the `enabled` flag and otherwise forward
|
|
78
|
-
* the caller's `rateLimit` verbatim, so better-auth's `window` (10s) / `max`
|
|
79
|
-
* (100) defaults and any custom rules still apply. Callers who genuinely
|
|
80
|
-
* want it off can pass `rateLimit: { enabled: false }` (e.g. when fronting
|
|
81
|
-
* auth with their own limiter), and any explicit `enabled` value wins.
|
|
82
|
-
*
|
|
83
|
-
* We also default `storage: "database"` — but only when rate limiting is not
|
|
84
|
-
* explicitly disabled (`enabled !== false`). Filling storage under a disabled
|
|
85
|
-
* limiter is harmless at runtime but makes `getAuthTables` emit an unused
|
|
86
|
-
* `rateLimit` table, so we skip it there.
|
|
87
|
-
*
|
|
88
|
-
* better-auth's own default is `storage: "memory"` — a per-isolate,
|
|
89
|
-
* non-durable counter. On Cloudflare Workers that means each isolate keeps
|
|
90
|
-
* its own tally, counters vanish on isolate recycle, and traffic spread
|
|
91
|
-
* across isolates never sums to the configured `max` — a limiter that
|
|
92
|
-
* reports "enabled" while never enforcing a global limit (the exact
|
|
93
|
-
* brute-force / credential-stuffing protection on `/sign-in`, OTP, and
|
|
94
|
-
* password-reset it is meant to buy). `storage: "database"` rides the counter
|
|
95
|
-
* through the configured `database` adapter — Lunora's store over the D1 auth
|
|
96
|
-
* tables — so the limit is durable *and* atomic (the store's native
|
|
97
|
-
* `incrementOne` gives a one-winner guarantee across isolates). Callers with
|
|
98
|
-
* their own durable store can pass an explicit `rateLimit: { storage: … }`
|
|
99
|
-
* (or `customStorage`), and any explicit value wins.
|
|
100
|
-
*
|
|
101
|
-
* Session cookie cache is ON by default too.
|
|
102
|
-
*
|
|
103
|
-
* Every authenticated call resolves identity through better-auth's
|
|
104
|
-
* `getSession`, which — without a cache — is a DB (D1) read on the hot path
|
|
105
|
-
* of every query/mutation/action that reads `ctx.auth` and of the WebSocket
|
|
106
|
-
* upgrade. better-auth's `session.cookieCache` carries the session payload in
|
|
107
|
-
* a short-lived signed cookie so `getSession` can answer without hitting the
|
|
108
|
-
* database until the cache window elapses. We default it on with a
|
|
109
|
-
* deliberately short 60s `maxAge` (better-auth's own default is 300s): long
|
|
110
|
-
* enough to erase the per-request read for a burst of calls, short enough
|
|
111
|
-
* that a revoked or role-changed session self-corrects within a minute.
|
|
112
|
-
* The one tradeoff — a revoked session stays valid until the cache expires —
|
|
113
|
-
* is bounded by that TTL; callers who need immediate revocation opt out with
|
|
114
|
-
* `session: { cookieCache: { enabled: false } }` (or the `strict` preset).
|
|
115
|
-
*
|
|
116
|
-
* Every explicit caller value is forwarded verbatim. The two `rateLimit` fills
|
|
117
|
-
* merge into a single `rateLimit` object so neither clobbers the other.
|
|
118
|
-
*/
|
|
119
|
-
declare const resolveAuthOptions: (options: LunoraAuthOptions) => LunoraAuthOptions;
|
|
120
|
-
/**
|
|
121
|
-
* Create the auth instance. Thin wrapper around `betterAuth` that enforces
|
|
122
|
-
* the `secret` requirement at construction time so misconfigured deployments
|
|
123
|
-
* fail loudly at the first fetch rather than the first sign-in attempt, then
|
|
124
|
-
* hands {@link resolveAuthOptions}'s hardened, default-filled options to
|
|
125
|
-
* better-auth.
|
|
126
|
-
*/
|
|
127
|
-
declare const createAuth: (options: LunoraAuthOptions) => LunoraAuth;
|
|
128
|
-
export { LunoraAuth as L, LunoraAuthOptions as a, createAuth as c, resolveAuthOptions as r };
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { betterAuth, BetterAuthOptions } from 'better-auth';
|
|
2
|
-
/**
|
|
3
|
-
* Lunora's options pass straight through to better-auth — the only thing we add
|
|
4
|
-
* is requiring `secret` up front so a misconfigured deployment fails loudly
|
|
5
|
-
* instead of at the first sign-in.
|
|
6
|
-
*
|
|
7
|
-
* For `database`, prefer `lunoraD1Adapter` (`database: lunoraD1Adapter(env.DB)`)
|
|
8
|
-
* over passing the raw `env.DB`. better-auth *does* accept a D1Database directly,
|
|
9
|
-
* but it then resolves its Kysely adapter via a runtime `await import(...)` inside
|
|
10
|
-
* `auth.$context` — and that import never settles under `@cloudflare/vite-plugin`'s
|
|
11
|
-
* worker runner, hanging every auth request in `pnpm dev`. The explicit adapter
|
|
12
|
-
* skips it, so dev and prod behave the same. (Raw `env.DB` is still correct for
|
|
13
|
-
* the migration-only instance — see `lunoraD1Adapter`'s note.)
|
|
14
|
-
*
|
|
15
|
-
* Session rotation / richer session policies are configured via the `session`
|
|
16
|
-
* field (a `SessionPolicy`); Lunora validates it for obviously-broken
|
|
17
|
-
* durations and forwards it verbatim to better-auth. See `sessionPresets`
|
|
18
|
-
* for ready-made rotation/expiry trade-offs.
|
|
19
|
-
*
|
|
20
|
-
* ## Serverless background tasks (Cloudflare Workers)
|
|
21
|
-
*
|
|
22
|
-
* better-auth runs some work *after* sending the response — most importantly the
|
|
23
|
-
* password-reset email, whose background send is what keeps reset responses
|
|
24
|
-
* constant-time (a timing-attack defence: the response doesn't reveal whether
|
|
25
|
-
* the account exists). On Cloudflare Workers a promise that isn't handed to
|
|
26
|
-
* `ctx.waitUntil` can be cancelled the moment the response returns, dropping
|
|
27
|
-
* that send and weakening the guarantee. Wire your request's `ctx.waitUntil`
|
|
28
|
-
* into better-auth's background handler so the work survives:
|
|
29
|
-
*
|
|
30
|
-
* ```ts
|
|
31
|
-
* // in your worker fetch handler, where `ctx: ExecutionContext` is in scope
|
|
32
|
-
* const auth = createAuth({
|
|
33
|
-
* secret: env.AUTH_SECRET,
|
|
34
|
-
* database: lunoraD1Adapter(env.DB),
|
|
35
|
-
* advanced: {
|
|
36
|
-
* backgroundTasks: { handler: (promise) => ctx.waitUntil(promise) },
|
|
37
|
-
* },
|
|
38
|
-
* });
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* (Lunora can't set this for you — `ctx.waitUntil` is per-request, but
|
|
42
|
-
* `createAuth` runs once at worker setup.)
|
|
43
|
-
*/
|
|
44
|
-
type LunoraAuthOptions = BetterAuthOptions;
|
|
45
|
-
/**
|
|
46
|
-
* The full better-auth instance: `auth.handler` accepts a `Request` and
|
|
47
|
-
* returns a `Response` (used by `handleAuthRequest`); `auth.api`
|
|
48
|
-
* exposes the typed endpoint surface for server-side calls (e.g.
|
|
49
|
-
* `auth.api.getSession({ headers })` inside a query/mutation).
|
|
50
|
-
*/
|
|
51
|
-
type LunoraAuth = ReturnType<typeof betterAuth>;
|
|
52
|
-
/**
|
|
53
|
-
* Resolve the caller's options into the exact shape `createAuth` hands to
|
|
54
|
-
* `betterAuth` — the hardened, default-filled options the running worker uses.
|
|
55
|
-
* Exported (and pure) so the migration path can compile the schema from the
|
|
56
|
-
* same resolved options: `compileMigrationsSql` routes through here, so the
|
|
57
|
-
* `rateLimit` table the worker's durable limiter writes to is included in the
|
|
58
|
-
* migration rather than silently omitted (it would be, if migrations saw the
|
|
59
|
-
* raw options while the worker ran the resolved ones).
|
|
60
|
-
*
|
|
61
|
-
* ## What it fills (each gated independently on caller silence)
|
|
62
|
-
*
|
|
63
|
-
* Secure-by-default cookies + secret-strength warning via {@link hardenAuthOptions},
|
|
64
|
-
* applied first so all hardening composes onto one options object.
|
|
65
|
-
*
|
|
66
|
-
* Rate limiting is ON by default for `/api/auth/*`.
|
|
67
|
-
*
|
|
68
|
-
* better-auth's own default is `rateLimit.enabled ?? isProduction`, and its
|
|
69
|
-
* `isProduction` is `"development" === "production"` resolved at
|
|
70
|
-
* module-load time. On Cloudflare Workers that check is unreliable: the
|
|
71
|
-
* runtime has no Node `process.env` (absent entirely without
|
|
72
|
-
* `nodejs_compat`, and even with it `NODE_ENV` is rarely `"production"` at
|
|
73
|
-
* request time). So better-auth would silently leave auth endpoints
|
|
74
|
-
* _unthrottled_ on a real deployment — the surprise we refuse to ship.
|
|
75
|
-
*
|
|
76
|
-
* We therefore default `enabled: true` whenever the caller hasn't made an
|
|
77
|
-
* explicit choice. We only fill the `enabled` flag and otherwise forward
|
|
78
|
-
* the caller's `rateLimit` verbatim, so better-auth's `window` (10s) / `max`
|
|
79
|
-
* (100) defaults and any custom rules still apply. Callers who genuinely
|
|
80
|
-
* want it off can pass `rateLimit: { enabled: false }` (e.g. when fronting
|
|
81
|
-
* auth with their own limiter), and any explicit `enabled` value wins.
|
|
82
|
-
*
|
|
83
|
-
* We also default `storage: "database"` — but only when rate limiting is not
|
|
84
|
-
* explicitly disabled (`enabled !== false`). Filling storage under a disabled
|
|
85
|
-
* limiter is harmless at runtime but makes `getAuthTables` emit an unused
|
|
86
|
-
* `rateLimit` table, so we skip it there.
|
|
87
|
-
*
|
|
88
|
-
* better-auth's own default is `storage: "memory"` — a per-isolate,
|
|
89
|
-
* non-durable counter. On Cloudflare Workers that means each isolate keeps
|
|
90
|
-
* its own tally, counters vanish on isolate recycle, and traffic spread
|
|
91
|
-
* across isolates never sums to the configured `max` — a limiter that
|
|
92
|
-
* reports "enabled" while never enforcing a global limit (the exact
|
|
93
|
-
* brute-force / credential-stuffing protection on `/sign-in`, OTP, and
|
|
94
|
-
* password-reset it is meant to buy). `storage: "database"` rides the counter
|
|
95
|
-
* through the configured `database` adapter — Lunora's store over the D1 auth
|
|
96
|
-
* tables — so the limit is durable *and* atomic (the store's native
|
|
97
|
-
* `incrementOne` gives a one-winner guarantee across isolates). Callers with
|
|
98
|
-
* their own durable store can pass an explicit `rateLimit: { storage: … }`
|
|
99
|
-
* (or `customStorage`), and any explicit value wins.
|
|
100
|
-
*
|
|
101
|
-
* Session cookie cache is ON by default too.
|
|
102
|
-
*
|
|
103
|
-
* Every authenticated call resolves identity through better-auth's
|
|
104
|
-
* `getSession`, which — without a cache — is a DB (D1) read on the hot path
|
|
105
|
-
* of every query/mutation/action that reads `ctx.auth` and of the WebSocket
|
|
106
|
-
* upgrade. better-auth's `session.cookieCache` carries the session payload in
|
|
107
|
-
* a short-lived signed cookie so `getSession` can answer without hitting the
|
|
108
|
-
* database until the cache window elapses. We default it on with a
|
|
109
|
-
* deliberately short 60s `maxAge` (better-auth's own default is 300s): long
|
|
110
|
-
* enough to erase the per-request read for a burst of calls, short enough
|
|
111
|
-
* that a revoked or role-changed session self-corrects within a minute.
|
|
112
|
-
* The one tradeoff — a revoked session stays valid until the cache expires —
|
|
113
|
-
* is bounded by that TTL; callers who need immediate revocation opt out with
|
|
114
|
-
* `session: { cookieCache: { enabled: false } }` (or the `strict` preset).
|
|
115
|
-
*
|
|
116
|
-
* Every explicit caller value is forwarded verbatim. The two `rateLimit` fills
|
|
117
|
-
* merge into a single `rateLimit` object so neither clobbers the other.
|
|
118
|
-
*/
|
|
119
|
-
declare const resolveAuthOptions: (options: LunoraAuthOptions) => LunoraAuthOptions;
|
|
120
|
-
/**
|
|
121
|
-
* Create the auth instance. Thin wrapper around `betterAuth` that enforces
|
|
122
|
-
* the `secret` requirement at construction time so misconfigured deployments
|
|
123
|
-
* fail loudly at the first fetch rather than the first sign-in attempt, then
|
|
124
|
-
* hands {@link resolveAuthOptions}'s hardened, default-filled options to
|
|
125
|
-
* better-auth.
|
|
126
|
-
*/
|
|
127
|
-
declare const createAuth: (options: LunoraAuthOptions) => LunoraAuth;
|
|
128
|
-
export { LunoraAuth as L, LunoraAuthOptions as a, createAuth as c, resolveAuthOptions as r };
|