@lunora/auth 1.0.0-alpha.262 → 1.0.0-alpha.263
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
|
@@ -96,7 +96,7 @@ For Cloudflare Turnstile on the **auth flow**, use the `captcha` plugin (`captch
|
|
|
96
96
|
|
|
97
97
|
### Disposable / free-email gating
|
|
98
98
|
|
|
99
|
-
Reject throwaway/disposable signups (and branch on free-vs-business email) by reusing the visulima email lists — pure-data and **edge-safe on the default path** (no DNS). Wire it into better-auth
|
|
99
|
+
Reject throwaway/disposable signups (and branch on free-vs-business email) by reusing the visulima email lists — pure-data and **edge-safe on the default path** (no DNS). Wire it into better-auth with `withEmailGate` (or `emailGateDatabaseHooks`). The gate runs on sign-up and on address changes (`/change-email`, the email-OTP change, admin updates); `onClassify` fires only at sign-up:
|
|
100
100
|
|
|
101
101
|
```ts
|
|
102
102
|
import { createAuth, withEmailGate, lunoraD1Adapter } from "@lunora/auth";
|
package/dist/index.d.mts
CHANGED
|
@@ -332,16 +332,18 @@ interface EmailGateHookConfig extends EmailGateConfig {
|
|
|
332
332
|
/**
|
|
333
333
|
* Called with the resolved classification once the gate passes, so app policy
|
|
334
334
|
* can react to `free` vs `business` at signup (e.g. tag the account). Never
|
|
335
|
-
* fires when the gate rejects.
|
|
336
|
-
*
|
|
335
|
+
* fires when the gate rejects. Fires only at creation: an address change never
|
|
336
|
+
* calls it, because its hook receives the patch rather than the new user record.
|
|
337
|
+
* `context` is better-auth's endpoint context (`null` outside a request, e.g. an
|
|
338
|
+
* internal create).
|
|
337
339
|
*/
|
|
338
340
|
onClassify?: (classification: EmailClassification, user: Record<string, unknown>, context: unknown) => void;
|
|
339
341
|
}
|
|
340
342
|
/**
|
|
341
|
-
* Produce a `databaseHooks` fragment that gates better-auth's
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
343
|
+
* Produce a `databaseHooks` fragment that gates better-auth's user lifecycle on the
|
|
344
|
+
* email-domain policy: sign-up (`user.create.before`) and address changes
|
|
345
|
+
* (`user.update.before`). Spread it into `createAuth({ databaseHooks: … })`, or
|
|
346
|
+
* use {@link withEmailGate} to merge it (composing with any existing hooks).
|
|
345
347
|
*
|
|
346
348
|
* ```ts
|
|
347
349
|
* const auth = createAuth({
|
|
@@ -353,10 +355,12 @@ interface EmailGateHookConfig extends EmailGateConfig {
|
|
|
353
355
|
*/
|
|
354
356
|
declare const emailGateDatabaseHooks: (config?: EmailGateHookConfig) => DatabaseHooks;
|
|
355
357
|
/**
|
|
356
|
-
* Merge the email-domain
|
|
357
|
-
* preserving any `databaseHooks` the caller already set.
|
|
358
|
-
*
|
|
359
|
-
* before their hook sees
|
|
358
|
+
* Merge the email-domain gate into an existing better-auth options object,
|
|
359
|
+
* preserving any `databaseHooks` the caller already set. For each hook the caller
|
|
360
|
+
* already declared (`user.create.before`, `user.update.before`), the gate runs
|
|
361
|
+
* first, rejecting a disallowed address before their hook sees it, then theirs
|
|
362
|
+
* runs on the (possibly rewritten) input. Other existing hooks, such as
|
|
363
|
+
* `user.update.after`, are kept as they were.
|
|
360
364
|
*
|
|
361
365
|
* ```ts
|
|
362
366
|
* const auth = createAuth(withEmailGate({ secret, database }, { blockDisposable: true }));
|
package/dist/index.d.ts
CHANGED
|
@@ -332,16 +332,18 @@ interface EmailGateHookConfig extends EmailGateConfig {
|
|
|
332
332
|
/**
|
|
333
333
|
* Called with the resolved classification once the gate passes, so app policy
|
|
334
334
|
* can react to `free` vs `business` at signup (e.g. tag the account). Never
|
|
335
|
-
* fires when the gate rejects.
|
|
336
|
-
*
|
|
335
|
+
* fires when the gate rejects. Fires only at creation: an address change never
|
|
336
|
+
* calls it, because its hook receives the patch rather than the new user record.
|
|
337
|
+
* `context` is better-auth's endpoint context (`null` outside a request, e.g. an
|
|
338
|
+
* internal create).
|
|
337
339
|
*/
|
|
338
340
|
onClassify?: (classification: EmailClassification, user: Record<string, unknown>, context: unknown) => void;
|
|
339
341
|
}
|
|
340
342
|
/**
|
|
341
|
-
* Produce a `databaseHooks` fragment that gates better-auth's
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
343
|
+
* Produce a `databaseHooks` fragment that gates better-auth's user lifecycle on the
|
|
344
|
+
* email-domain policy: sign-up (`user.create.before`) and address changes
|
|
345
|
+
* (`user.update.before`). Spread it into `createAuth({ databaseHooks: … })`, or
|
|
346
|
+
* use {@link withEmailGate} to merge it (composing with any existing hooks).
|
|
345
347
|
*
|
|
346
348
|
* ```ts
|
|
347
349
|
* const auth = createAuth({
|
|
@@ -353,10 +355,12 @@ interface EmailGateHookConfig extends EmailGateConfig {
|
|
|
353
355
|
*/
|
|
354
356
|
declare const emailGateDatabaseHooks: (config?: EmailGateHookConfig) => DatabaseHooks;
|
|
355
357
|
/**
|
|
356
|
-
* Merge the email-domain
|
|
357
|
-
* preserving any `databaseHooks` the caller already set.
|
|
358
|
-
*
|
|
359
|
-
* before their hook sees
|
|
358
|
+
* Merge the email-domain gate into an existing better-auth options object,
|
|
359
|
+
* preserving any `databaseHooks` the caller already set. For each hook the caller
|
|
360
|
+
* already declared (`user.create.before`, `user.update.before`), the gate runs
|
|
361
|
+
* first, rejecting a disallowed address before their hook sees it, then theirs
|
|
362
|
+
* runs on the (possibly rewritten) input. Other existing hooks, such as
|
|
363
|
+
* `user.update.after`, are kept as they were.
|
|
360
364
|
*
|
|
361
365
|
* ```ts
|
|
362
366
|
* const auth = createAuth(withEmailGate({ secret, database }, { blockDisposable: true }));
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{l as r,a as o,b as a}from"./packem_shared/adapter-CBZ17jKi.mjs";import{LunoraAuthAdminError as s,createAuthAdmin as u}from"./packem_shared/LunoraAuthAdminError-CxXGd3ni.mjs";import{AUTH_AUDIT_TABLE as A,appendAuthAuditEntry as m,createAuthAuditReader as p,ensureAuthAuditTable as h,readAuthAuditLog as l}from"./audit.mjs";import{authAuditHook as f,buildAuditEntry as x,eventForPath as E,withAuthAudit as D}from"./packem_shared/authAuditHook-DPTKdjBe.mjs";import{R as S,I as c,a as v,L as _}from"./packem_shared/auth-do-DHxBZtyS.mjs";import{createAuth as U,resolveAuthOptions as y}from"./packem_shared/createAuth-Dioo_-mD.mjs";import{authDiscoveryPaths as P,authDiscoveryPathsFor as L,handleAuthDiscoveryRequest as g}from"./packem_shared/authDiscoveryPaths-BtKCs_3V.mjs";import{authDoColumnAdditions as O,authDoSchemaStatements as w}from"./packem_shared/authDoColumnAdditions-UwF3Rl41.mjs";import{createDoAuthWiring as F}from"./packem_shared/createDoAuthWiring-BXyBVIda.mjs";import{emailGateDatabaseHooks as k,withEmailGate as q}from"./packem_shared/emailGateDatabaseHooks-
|
|
1
|
+
import{l as r,a as o,b as a}from"./packem_shared/adapter-CBZ17jKi.mjs";import{LunoraAuthAdminError as s,createAuthAdmin as u}from"./packem_shared/LunoraAuthAdminError-CxXGd3ni.mjs";import{AUTH_AUDIT_TABLE as A,appendAuthAuditEntry as m,createAuthAuditReader as p,ensureAuthAuditTable as h,readAuthAuditLog as l}from"./audit.mjs";import{authAuditHook as f,buildAuditEntry as x,eventForPath as E,withAuthAudit as D}from"./packem_shared/authAuditHook-DPTKdjBe.mjs";import{R as S,I as c,a as v,L as _}from"./packem_shared/auth-do-DHxBZtyS.mjs";import{createAuth as U,resolveAuthOptions as y}from"./packem_shared/createAuth-Dioo_-mD.mjs";import{authDiscoveryPaths as P,authDiscoveryPathsFor as L,handleAuthDiscoveryRequest as g}from"./packem_shared/authDiscoveryPaths-BtKCs_3V.mjs";import{authDoColumnAdditions as O,authDoSchemaStatements as w}from"./packem_shared/authDoColumnAdditions-UwF3Rl41.mjs";import{createDoAuthWiring as F}from"./packem_shared/createDoAuthWiring-BXyBVIda.mjs";import{emailGateDatabaseHooks as k,withEmailGate as q}from"./packem_shared/emailGateDatabaseHooks-Dvyliwxx.mjs";import{assertEmailAllowed as G,classifyEmail as M,emailGateMiddleware as B,loadEmailDomainLists as W}from"./email-guard.mjs";import{default as Y}from"./packem_shared/isDevEnvironment-yLbPngwn.mjs";import{handleAuthRequest as z}from"./packem_shared/handleAuthRequest-Id9Vv_Tk.mjs";import{createSignUpInvitation as K,listSignUpInvitations as Q,pruneSignUpInvitations as X,revokeSignUpInvitation as Z}from"./packem_shared/createSignUpInvitation-CwrPh0XH.mjs";import{legacyIssuerCleanupStatements as tt}from"./packem_shared/legacyIssuerCleanupStatements-D9Kf8OD1.mjs";import{LunoraAuthHeadersError as rt,withAuthPlugins as ot}from"./middleware.mjs";import{default as it}from"./schema.mjs";import{sessionPresets as ut,validateSessionPolicy as nt}from"./packem_shared/sessionPresets-C867Mlo4.mjs";import{resolveSessionIdentity as mt}from"./packem_shared/resolveSessionIdentity-CNjGy6Pb.mjs";import{c as ht,d as lt}from"./packem_shared/sql-store-uMubPYI9.mjs";import{createMemoryAuthStore as ft,matchesWhere as xt}from"./store.mjs";import{TURNSTILE_VERIFY_ENDPOINT as Dt,verifyTurnstile as Tt}from"./turnstile.mjs";import{verifyTurnstileMiddleware as ct}from"./turnstile-middleware.mjs";import{DEFAULT_AUTH_BASE_PATH as _t}from"./packem_shared/DEFAULT_AUTH_BASE_PATH-C3SqYG3N.mjs";export{A as AUTH_AUDIT_TABLE,S as AUTH_DO_AUDIT_PATH,c as AUTH_DO_SECRET_HEADER,v as AUTH_DO_SESSION_PATH,_t as DEFAULT_AUTH_BASE_PATH,s as LunoraAuthAdminError,_ as LunoraAuthDO,rt as LunoraAuthHeadersError,Dt as TURNSTILE_VERIFY_ENDPOINT,m as appendAuthAuditEntry,G as assertEmailAllowed,f as authAuditHook,P as authDiscoveryPaths,L as authDiscoveryPathsFor,O as authDoColumnAdditions,w as authDoSchemaStatements,it as authTables,x as buildAuditEntry,M as classifyEmail,U as createAuth,u as createAuthAdmin,p as createAuthAuditReader,F as createDoAuthWiring,ft as createMemoryAuthStore,K as createSignUpInvitation,ht as createSqlAuthStore,lt as d1Executor,k as emailGateDatabaseHooks,B as emailGateMiddleware,h as ensureAuthAuditTable,E as eventForPath,g as handleAuthDiscoveryRequest,z as handleAuthRequest,Y as isDevEnvironment,tt as legacyIssuerCleanupStatements,Q as listSignUpInvitations,W as loadEmailDomainLists,r as lunoraAuthAdapter,o as lunoraD1Adapter,a as lunoraDoAdapter,xt as matchesWhere,X as pruneSignUpInvitations,l as readAuthAuditLog,y as resolveAuthOptions,mt as resolveSessionIdentity,Z as revokeSignUpInvitation,ut as sessionPresets,nt as validateSessionPolicy,Tt as verifyTurnstile,ct as verifyTurnstileMiddleware,D as withAuthAudit,ot as withAuthPlugins,q as withEmailGate};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as k}from"@lunora/errors";import{APIError as l}from"better-auth/api";import{assertEmailAllowed as R}from"../email-guard.mjs";const y=e=>{switch(e){case 400:return"BAD_REQUEST";case 422:return"UNPROCESSABLE_ENTITY";case 429:return"TOO_MANY_REQUESTS";default:return"INTERNAL_SERVER_ERROR"}},f=async(e,a,r)=>{try{return await R(e,{...a,lists:r})}catch(t){throw t instanceof k?new l(y(t.status),{code:t.code,message:t.message}):t}},u=e=>async(a,r)=>{const t=typeof a.email=="string"?a.email:void 0;if(t===void 0||t==="")return;const o=e.onClassify!==void 0,i=await f(t,e,{disposable:e.blockDisposable!==!1||o,free:o});e.onClassify?.(i,a,r)},b=e=>async a=>{if(a.email!==void 0){if(typeof a.email!="string"||a.email==="")throw new l("BAD_REQUEST",{code:"VALIDATION_ERROR",message:"email must be a non-empty string"});await f(a.email,e,{disposable:e.blockDisposable!==!1,free:!1})}},A=(e,a)=>typeof e=="object"&&e!==null&&"data"in e?{...a,...e.data}:a,T=(e={})=>({user:{create:{before:u(e)},update:{before:b(e)}}}),U=(e,a={})=>{const r=u(a),t=b(a),o=e.databaseHooks?.user?.create?.before,i=e.databaseHooks?.user?.update?.before,m=o?async(s,n)=>(await r(s,n),o(s,n)):r,E=i?async(s,n)=>{await t(s);const w=s.email,c=await i(s,n),d=A(c,s);return d.email!==w&&await t(d),c}:t;return{...e,databaseHooks:{...e.databaseHooks,user:{...e.databaseHooks?.user,create:{...e.databaseHooks?.user?.create,before:m},update:{...e.databaseHooks?.user?.update,before:E}}}}};export{T as emailGateDatabaseHooks,U as withEmailGate};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as n}from"@lunora/errors";import{APIError as l}from"better-auth/api";import{assertEmailAllowed as d}from"../email-guard.mjs";const u=e=>{switch(e){case 400:return"BAD_REQUEST";case 422:return"UNPROCESSABLE_ENTITY";case 429:return"TOO_MANY_REQUESTS";default:return"INTERNAL_SERVER_ERROR"}},c=e=>async(r,t)=>{const s=typeof r.email=="string"?r.email:void 0;if(s===void 0||s==="")return;let o;try{const a=e.onClassify!==void 0;o=await d(s,{...e,lists:{disposable:e.blockDisposable!==!1||a,free:a}})}catch(a){throw a instanceof n?new l(u(a.status),{code:a.code,message:a.message}):a}e.onClassify?.(o,r,t)},m=(e={})=>({user:{create:{before:c(e)}}}),R=(e,r={})=>{const t=c(r),s=e.databaseHooks?.user?.create?.before,o=s?async(a,i)=>(await t(a,i),s(a,i)):t;return{...e,databaseHooks:{...e.databaseHooks,user:{...e.databaseHooks?.user,create:{...e.databaseHooks?.user?.create,before:o}}}}};export{m as emailGateDatabaseHooks,R as withEmailGate};
|