@lunora/auth 1.0.0-alpha.163 → 1.0.0-alpha.165

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.
@@ -0,0 +1 @@
1
+ import{oauthProviderClient as m}from"@better-auth/oauth-provider/client";import{passkeyClient as h}from"@better-auth/passkey/client";import{oneTapClient as g,lastLoginMethodClient as d,deviceAuthorizationClient as p,anonymousClient as C,multiSessionClient as y,phoneNumberClient as f,usernameClient as S,adminClient as T,emailOTPClient as L,magicLinkClient as b,twoFactorClient as P,organizationClient as k}from"better-auth/client/plugins";const i=Symbol.for("lunora:session-change-listeners"),v=()=>{const n=globalThis;let o=n[i];return o===void 0&&(o=new Set,n[i]=o),o},r=async()=>{const n=[];for(const o of v())try{n.push(o())}catch{}await Promise.allSettled(n)},s={organization:k,twoFactor:P,passkey:h,magicLink:b,emailOtp:L,admin:T,username:S,phoneNumber:f,multiSession:y,anonymous:C,deviceAuthorization:p,lastLoginMethod:d,oauthProvider:m},A=(n={})=>{const o=[];for(const e of Object.keys(s))n[e]&&o.push(s[e]());return o},E=()=>globalThis.location?.origin,z=async()=>r(),I=()=>({fetchPlugins:[{hooks:{onSuccess:n=>{(n.request.method??"GET").toUpperCase()!=="GET"&&r().catch(()=>{})}},id:"lunora-session-sync",name:"lunora-session-sync"}],id:"lunora-session-sync"}),G=(n,o={})=>{const{baseURL:e,extraPlugins:a=[],oneTapClientId:t,plugins:l,...c}=o,u=t===void 0||t===""?[]:[g({clientId:t})];return n({...c,baseURL:e??E(),plugins:[I(),...A(l),...u,...a]})};export{G as createLunoraAuthClient,A as lunoraAuthPlugins,I as lunoraSessionSync,z as notifyLunoraSessionChange};
@@ -46,6 +46,55 @@ interface CreateLunoraAuthClientOptions {
46
46
  /** Which standard client plugins to include. */
47
47
  plugins?: LunoraAuthPluginToggles;
48
48
  }
49
+ /**
50
+ * What {@link lunoraSessionSync} returns: a better-auth client plugin, typed
51
+ * narrowly rather than as `BetterAuthClientPlugin` — widening a plugin to that
52
+ * type collapses better-auth's session inference on the client it joins.
53
+ */
54
+ interface LunoraSessionSyncPlugin {
55
+ fetchPlugins: {
56
+ hooks: {
57
+ onSuccess: (context: {
58
+ request: {
59
+ method?: string;
60
+ };
61
+ }) => void;
62
+ };
63
+ id: string;
64
+ name: string;
65
+ }[];
66
+ id: "lunora-session-sync";
67
+ }
68
+ /**
69
+ * Tell every `LunoraClient` in the page that the auth session may have changed,
70
+ * so each asks `/get-session` who is signed in now.
71
+ *
72
+ * Needed for a **cookie** session: a sign-in or sign-out sets or clears an
73
+ * `HttpOnly` cookie in a request the Lunora client never sees, and nothing it
74
+ * can observe changes. Until it re-resolves, its live queries keep showing the
75
+ * previous user's rows over a socket still authenticated as them.
76
+ * {@link lunoraSessionSync} (installed by {@link createLunoraAuthClient}) and
77
+ * `@lunora/auth-ui` call it for you; call it yourself after a session change
78
+ * made any other way.
79
+ *
80
+ * Resolves once every client has re-resolved (or failed to), so code that
81
+ * reads `client.currentIdentity()` next can `await` it. Never rejects.
82
+ */
83
+ declare const notifyLunoraSessionChange: () => Promise<void>;
84
+ /**
85
+ * A better-auth client plugin that, after every successful auth request that
86
+ * can change the session (anything but a `GET` — sign-in, sign-up, sign-out,
87
+ * 2FA, account switch, session revocation), calls
88
+ * {@link notifyLunoraSessionChange}.
89
+ *
90
+ * {@link createLunoraAuthClient} always installs it. Add it yourself when you
91
+ * call `createAuthClient` directly:
92
+ *
93
+ * ```ts
94
+ * export const authClient = createAuthClient({ plugins: [lunoraSessionSync()] });
95
+ * ```
96
+ */
97
+ declare const lunoraSessionSync: () => LunoraSessionSyncPlugin;
49
98
  /**
50
99
  * Build a better-auth client with Lunora's standard plugin set from toggles.
51
100
  *
@@ -163,4 +212,36 @@ type LunoraAuthClientPlugin,
163
212
  * to `createAuth`: a server plugin without its client counterpart leaves
164
213
  * those actions untyped/unavailable, and vice-versa.
165
214
  */
166
- type LunoraAuthPluginToggles, createLunoraAuthClient, lunoraAuthPlugins };
215
+ type LunoraAuthPluginToggles,
216
+ /**
217
+ * Client-side counterparts to the server plugins re-exported from
218
+ * `@lunora/auth/plugins`, surfaced under `@lunora/auth/plugins/client`.
219
+ *
220
+ * better-auth plugins come in two halves: a **server** plugin you pass to
221
+ * `betterAuth()` (re-exported from `@lunora/auth/plugins`) and a **client**
222
+ * plugin you pass to `createAuthClient()`. Both halves must be registered for a
223
+ * plugin's endpoints, inferred types, and client actions (e.g.
224
+ * `authClient.twoFactor.*`, `authClient.organization.*`, the `twoFactorRedirect`
225
+ * sign-in flow) to exist. This module is the client half so consumers don't have
226
+ * to reach into better-auth's `better-auth/client/plugins` subpath directly.
227
+ *
228
+ * # Wiring
229
+ *
230
+ * ```ts
231
+ * import { createAuthClient } from "better-auth/client"; // or a framework adapter
232
+ * import { organizationClient, twoFactorClient } from "@lunora/auth/plugins/client";
233
+ *
234
+ * export const authClient = createAuthClient({
235
+ * baseURL: import.meta.env.VITE_AUTH_URL,
236
+ * plugins: [
237
+ * organizationClient(),
238
+ * twoFactorClient({ onTwoFactorRedirect: () => location.assign("/2fa") }),
239
+ * ],
240
+ * });
241
+ * ```
242
+ *
243
+ * Keep the client plugin list in parity with the server `plugins` array passed
244
+ * to `createAuth`: a server plugin without its client counterpart leaves
245
+ * those actions untyped/unavailable, and vice-versa.
246
+ */
247
+ type LunoraSessionSyncPlugin, createLunoraAuthClient, lunoraAuthPlugins, lunoraSessionSync, notifyLunoraSessionChange };
@@ -46,6 +46,55 @@ interface CreateLunoraAuthClientOptions {
46
46
  /** Which standard client plugins to include. */
47
47
  plugins?: LunoraAuthPluginToggles;
48
48
  }
49
+ /**
50
+ * What {@link lunoraSessionSync} returns: a better-auth client plugin, typed
51
+ * narrowly rather than as `BetterAuthClientPlugin` — widening a plugin to that
52
+ * type collapses better-auth's session inference on the client it joins.
53
+ */
54
+ interface LunoraSessionSyncPlugin {
55
+ fetchPlugins: {
56
+ hooks: {
57
+ onSuccess: (context: {
58
+ request: {
59
+ method?: string;
60
+ };
61
+ }) => void;
62
+ };
63
+ id: string;
64
+ name: string;
65
+ }[];
66
+ id: "lunora-session-sync";
67
+ }
68
+ /**
69
+ * Tell every `LunoraClient` in the page that the auth session may have changed,
70
+ * so each asks `/get-session` who is signed in now.
71
+ *
72
+ * Needed for a **cookie** session: a sign-in or sign-out sets or clears an
73
+ * `HttpOnly` cookie in a request the Lunora client never sees, and nothing it
74
+ * can observe changes. Until it re-resolves, its live queries keep showing the
75
+ * previous user's rows over a socket still authenticated as them.
76
+ * {@link lunoraSessionSync} (installed by {@link createLunoraAuthClient}) and
77
+ * `@lunora/auth-ui` call it for you; call it yourself after a session change
78
+ * made any other way.
79
+ *
80
+ * Resolves once every client has re-resolved (or failed to), so code that
81
+ * reads `client.currentIdentity()` next can `await` it. Never rejects.
82
+ */
83
+ declare const notifyLunoraSessionChange: () => Promise<void>;
84
+ /**
85
+ * A better-auth client plugin that, after every successful auth request that
86
+ * can change the session (anything but a `GET` — sign-in, sign-up, sign-out,
87
+ * 2FA, account switch, session revocation), calls
88
+ * {@link notifyLunoraSessionChange}.
89
+ *
90
+ * {@link createLunoraAuthClient} always installs it. Add it yourself when you
91
+ * call `createAuthClient` directly:
92
+ *
93
+ * ```ts
94
+ * export const authClient = createAuthClient({ plugins: [lunoraSessionSync()] });
95
+ * ```
96
+ */
97
+ declare const lunoraSessionSync: () => LunoraSessionSyncPlugin;
49
98
  /**
50
99
  * Build a better-auth client with Lunora's standard plugin set from toggles.
51
100
  *
@@ -163,4 +212,36 @@ type LunoraAuthClientPlugin,
163
212
  * to `createAuth`: a server plugin without its client counterpart leaves
164
213
  * those actions untyped/unavailable, and vice-versa.
165
214
  */
166
- type LunoraAuthPluginToggles, createLunoraAuthClient, lunoraAuthPlugins };
215
+ type LunoraAuthPluginToggles,
216
+ /**
217
+ * Client-side counterparts to the server plugins re-exported from
218
+ * `@lunora/auth/plugins`, surfaced under `@lunora/auth/plugins/client`.
219
+ *
220
+ * better-auth plugins come in two halves: a **server** plugin you pass to
221
+ * `betterAuth()` (re-exported from `@lunora/auth/plugins`) and a **client**
222
+ * plugin you pass to `createAuthClient()`. Both halves must be registered for a
223
+ * plugin's endpoints, inferred types, and client actions (e.g.
224
+ * `authClient.twoFactor.*`, `authClient.organization.*`, the `twoFactorRedirect`
225
+ * sign-in flow) to exist. This module is the client half so consumers don't have
226
+ * to reach into better-auth's `better-auth/client/plugins` subpath directly.
227
+ *
228
+ * # Wiring
229
+ *
230
+ * ```ts
231
+ * import { createAuthClient } from "better-auth/client"; // or a framework adapter
232
+ * import { organizationClient, twoFactorClient } from "@lunora/auth/plugins/client";
233
+ *
234
+ * export const authClient = createAuthClient({
235
+ * baseURL: import.meta.env.VITE_AUTH_URL,
236
+ * plugins: [
237
+ * organizationClient(),
238
+ * twoFactorClient({ onTwoFactorRedirect: () => location.assign("/2fa") }),
239
+ * ],
240
+ * });
241
+ * ```
242
+ *
243
+ * Keep the client plugin list in parity with the server `plugins` array passed
244
+ * to `createAuth`: a server plugin without its client counterpart leaves
245
+ * those actions untyped/unavailable, and vice-versa.
246
+ */
247
+ type LunoraSessionSyncPlugin, createLunoraAuthClient, lunoraAuthPlugins, lunoraSessionSync, notifyLunoraSessionChange };
@@ -1 +1 @@
1
- import{createLunoraAuthClient as t,lunoraAuthPlugins as n}from"./packem_shared/createLunoraAuthClient-DhjhCwmM.mjs";import{apiKeyClient as l}from"@better-auth/api-key/client";import{oauthDeviceAuthorizationClient as a,oauthProviderClient as C}from"@better-auth/oauth-provider/client";import{passkeyClient as s}from"@better-auth/passkey/client";import{adminClient as d,anonymousClient as p,customSessionClient as h,deviceAuthorizationClient as f,emailOTPClient as c,inferAdditionalFields as A,inferOrgAdditionalFields as g,jwtClient as x,lastLoginMethodClient as T,magicLinkClient as k,multiSessionClient as v,oneTapClient as w,oneTimeTokenClient as y,organizationClient as z,phoneNumberClient as F,siweClient as L,twoFactorClient as P,usernameClient as O}from"better-auth/client/plugins";export{d as adminClient,p as anonymousClient,l as apiKeyClient,t as createLunoraAuthClient,h as customSessionClient,f as deviceAuthorizationClient,c as emailOTPClient,A as inferAdditionalFields,g as inferOrgAdditionalFields,x as jwtClient,T as lastLoginMethodClient,n as lunoraAuthPlugins,k as magicLinkClient,v as multiSessionClient,a as oauthDeviceAuthorizationClient,C as oauthProviderClient,w as oneTapClient,y as oneTimeTokenClient,z as organizationClient,s as passkeyClient,F as phoneNumberClient,L as siweClient,P as twoFactorClient,O as usernameClient};
1
+ import{createLunoraAuthClient as n,lunoraAuthPlugins as t,lunoraSessionSync as o,notifyLunoraSessionChange as l}from"./packem_shared/createLunoraAuthClient-DZwrWj-w.mjs";import{apiKeyClient as a}from"@better-auth/api-key/client";import{oauthDeviceAuthorizationClient as s,oauthProviderClient as u}from"@better-auth/oauth-provider/client";import{passkeyClient as d}from"@better-auth/passkey/client";import{adminClient as p,anonymousClient as f,customSessionClient as c,deviceAuthorizationClient as g,emailOTPClient as A,inferAdditionalFields as x,inferOrgAdditionalFields as y,jwtClient as S,lastLoginMethodClient as L,magicLinkClient as T,multiSessionClient as k,oneTapClient as v,oneTimeTokenClient as w,organizationClient as z,phoneNumberClient as F,siweClient as P,twoFactorClient as O,usernameClient as b}from"better-auth/client/plugins";export{p as adminClient,f as anonymousClient,a as apiKeyClient,n as createLunoraAuthClient,c as customSessionClient,g as deviceAuthorizationClient,A as emailOTPClient,x as inferAdditionalFields,y as inferOrgAdditionalFields,S as jwtClient,L as lastLoginMethodClient,t as lunoraAuthPlugins,o as lunoraSessionSync,T as magicLinkClient,k as multiSessionClient,l as notifyLunoraSessionChange,s as oauthDeviceAuthorizationClient,u as oauthProviderClient,v as oneTapClient,w as oneTimeTokenClient,z as organizationClient,d as passkeyClient,F as phoneNumberClient,P as siweClient,O as twoFactorClient,b as usernameClient};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/auth",
3
- "version": "1.0.0-alpha.163",
3
+ "version": "1.0.0-alpha.165",
4
4
  "description": "Auth for Lunora — a thin better-auth wrapper: email/password, OAuth, plugins, D1-backed",
5
5
  "keywords": [
6
6
  "auth",
@@ -103,8 +103,8 @@
103
103
  "@better-auth/oauth-provider": "1.7.3",
104
104
  "@better-auth/passkey": "1.7.3",
105
105
  "@better-auth/scim": "1.7.3",
106
- "@lunora/errors": "1.0.0-alpha.42",
107
- "@lunora/values": "1.0.0-alpha.53",
106
+ "@lunora/errors": "1.0.0-alpha.43",
107
+ "@lunora/values": "1.0.0-alpha.54",
108
108
  "@visulima/disposable-email-domains": "1.1.1",
109
109
  "@visulima/email-verifier": "1.0.9",
110
110
  "@visulima/free-email-domains": "1.0.1",
@@ -1 +0,0 @@
1
- import{oauthProviderClient as u}from"@better-auth/oauth-provider/client";import{passkeyClient as m}from"@better-auth/passkey/client";import{oneTapClient as c,lastLoginMethodClient as C,deviceAuthorizationClient as p,anonymousClient as g,multiSessionClient as h,phoneNumberClient as d,usernameClient as L,adminClient as b,emailOTPClient as f,magicLinkClient as k,twoFactorClient as y,organizationClient as P}from"better-auth/client/plugins";const o={organization:P,twoFactor:y,passkey:m,magicLink:k,emailOtp:f,admin:b,username:L,phoneNumber:d,multiSession:h,anonymous:g,deviceAuthorization:p,lastLoginMethod:C,oauthProvider:u},T=(t={})=>{const n=[];for(const i of Object.keys(o))t[i]&&n.push(o[i]());return n},v=()=>globalThis.location?.origin,I=(t,n={})=>{const{baseURL:i,extraPlugins:a=[],oneTapClientId:e,plugins:r,...s}=n,l=e===void 0||e===""?[]:[c({clientId:e})];return t({...s,baseURL:i??v(),plugins:[...T(r),...l,...a]})};export{I as createLunoraAuthClient,T as lunoraAuthPlugins};