@rio.js/enterprise 1.4.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 +89 -0
- package/dist/adapter-factory-BTRALCLD-kJBwe70v.mjs +836 -0
- package/dist/better-auth-CStoaWiq.d.mts +10 -0
- package/dist/better-auth-CqfhQJYE.mjs +558 -0
- package/dist/better-auth.d.mts +2 -0
- package/dist/better-auth.mjs +17 -0
- package/dist/bun-sqlite-dialect-2R9nCsVF-DFs6tpGr.mjs +155 -0
- package/dist/client--1_AEBPu-8Ae9icC9.mjs +125 -0
- package/dist/client.d.mts +17 -0
- package/dist/client.mjs +381 -0
- package/dist/db-BVXTgOd3.mjs +681 -0
- package/dist/db-BadqSwVl.d.mts +9542 -0
- package/dist/db-schema.final-DWleoQm0.mjs +785 -0
- package/dist/db.d.mts +2 -0
- package/dist/db.mjs +3 -0
- package/dist/dialect-C6_pK3V9-CPJHWkYR.mjs +72 -0
- package/dist/dist-CygcgJYk.mjs +422 -0
- package/dist/env-DwlNAN_D-C1zHd0cf-Cdlw8sNp.mjs +289 -0
- package/dist/esm-C5TuvtGn.mjs +15816 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +17 -0
- package/dist/init-D8lwWc90.mjs +27 -0
- package/dist/json-oFuWgANh-O1U6k3bL.mjs +3811 -0
- package/dist/kysely-adapter-D_seG51p.mjs +297 -0
- package/dist/memory-adapter-CY-oDozb.mjs +215 -0
- package/dist/misc-CbURQDlR-sLtUwwQY.mjs +7 -0
- package/dist/node-sqlite-dialect-CdC7L-ji-QLbJGmDc.mjs +155 -0
- package/dist/parser-bL7W2mQ0-YdTgjtji.mjs +140 -0
- package/dist/plugins-BNFht2HW.mjs +23358 -0
- package/dist/plugins.d.mts +1 -0
- package/dist/plugins.mjs +13 -0
- package/dist/react--VZQu7s1.mjs +560 -0
- package/dist/react.d.mts +1 -0
- package/dist/react.mjs +6 -0
- package/dist/server.d.mts +10 -0
- package/dist/server.mjs +45 -0
- package/dist/social-providers-DNfE9Ak7-Be5zMAEe.mjs +2920 -0
- package/dist/social-providers.d.mts +1 -0
- package/dist/social-providers.mjs +6 -0
- package/dist/verify-CN5Qc0e-.mjs +1183 -0
- package/package.json +98 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "better-auth/plugins";
|
package/dist/plugins.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { s as HIDE_METADATA } from "./json-oFuWgANh-O1U6k3bL.mjs";
|
|
2
|
+
import "./env-DwlNAN_D-C1zHd0cf-Cdlw8sNp.mjs";
|
|
3
|
+
import "./verify-CN5Qc0e-.mjs";
|
|
4
|
+
import "./social-providers-DNfE9Ak7-Be5zMAEe.mjs";
|
|
5
|
+
import { $ as jwt, A as apiKey, B as oAuthDiscoveryMetadata, C as captcha, D as API_KEY_TABLE_NAME, E as admin, F as getMCPProtectedResourceMetadata, G as AuthzedSyncClient, H as oneTimeToken, I as getMCPProviderMetadata, J as getMetadata, K as graph, M as assetsClient, O as ERROR_CODES, P as defaultKeyHasher, Q as getJwtToken, R as lastLoginMethod, S as customSession, T as anonymous, U as organization, V as oAuthProtectedResourceMetadata, W as withMcpAuth, X as createJwk, Y as oidcProvider, Z as generateExportedKeyPair, _ as okta, a as openAPI, b as deviceAuthorization, c as multiSession, d as auth0, et as verifyJWT, f as genericOAuth, ft as createAuthEndpoint, g as microsoftEntraId, h as line, i as phoneNumber, j as assets, k as agents, l as magicLink, m as keycloak, mt as optionsMiddleware, n as username, o as oneTap, p as hubspot, pt as createAuthMiddleware, q as getClient, r as siwe, rt as twoFactor, s as oAuthProxy, t as USERNAME_ERROR_CODES, tt as TWO_FACTOR_ERROR_CODES, u as haveIBeenPwned, v as slack, w as bearer, x as deviceAuthorizationOptionsSchema, y as emailOTP, z as mcp } from "./plugins-BNFht2HW.mjs";
|
|
6
|
+
import "./esm-C5TuvtGn.mjs";
|
|
7
|
+
import "./dialect-C6_pK3V9-CPJHWkYR.mjs";
|
|
8
|
+
import "./dist-CygcgJYk.mjs";
|
|
9
|
+
import "./misc-CbURQDlR-sLtUwwQY.mjs";
|
|
10
|
+
import "./parser-bL7W2mQ0-YdTgjtji.mjs";
|
|
11
|
+
import { a as role, r as createAccessControl, t as twoFactorClient } from "./client--1_AEBPu-8Ae9icC9.mjs";
|
|
12
|
+
|
|
13
|
+
export { API_KEY_TABLE_NAME, AuthzedSyncClient, ERROR_CODES, HIDE_METADATA, TWO_FACTOR_ERROR_CODES, USERNAME_ERROR_CODES, admin, agents, anonymous, apiKey, assets, assetsClient, auth0, bearer, captcha, createAccessControl, createAuthEndpoint, createAuthMiddleware, createJwk, customSession, defaultKeyHasher, deviceAuthorization, deviceAuthorizationOptionsSchema, emailOTP, generateExportedKeyPair, genericOAuth, getClient, getJwtToken, getMCPProtectedResourceMetadata, getMCPProviderMetadata, getMetadata, graph, haveIBeenPwned, hubspot, jwt, keycloak, lastLoginMethod, line, magicLink, mcp, microsoftEntraId, multiSession, oAuthDiscoveryMetadata, oAuthProtectedResourceMetadata, oAuthProxy, oidcProvider, okta, oneTap, oneTimeToken, openAPI, optionsMiddleware, organization, phoneNumber, role, siwe, slack, twoFactor, twoFactorClient, username, verifyJWT, withMcpAuth };
|
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
import { n as createFetch } from "./dist-CygcgJYk.mjs";
|
|
2
|
+
import { r as getBaseURL, t as parseJSON } from "./parser-bL7W2mQ0-YdTgjtji.mjs";
|
|
3
|
+
import { atom, listenKeys, onMount } from "nanostores";
|
|
4
|
+
import { useCallback, useRef, useSyncExternalStore } from "react";
|
|
5
|
+
|
|
6
|
+
//#region ../better-auth/dist/proxy-Cm3asZSg.mjs
|
|
7
|
+
const kBroadcastChannel = Symbol.for("better-auth:broadcast-channel");
|
|
8
|
+
const now$1 = () => Math.floor(Date.now() / 1e3);
|
|
9
|
+
var WindowBroadcastChannel = class {
|
|
10
|
+
listeners = /* @__PURE__ */ new Set();
|
|
11
|
+
name;
|
|
12
|
+
constructor(name = "better-auth.message") {
|
|
13
|
+
this.name = name;
|
|
14
|
+
}
|
|
15
|
+
subscribe(listener) {
|
|
16
|
+
this.listeners.add(listener);
|
|
17
|
+
return () => {
|
|
18
|
+
this.listeners.delete(listener);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
post(message) {
|
|
22
|
+
if (typeof window === "undefined") return;
|
|
23
|
+
try {
|
|
24
|
+
localStorage.setItem(this.name, JSON.stringify({
|
|
25
|
+
...message,
|
|
26
|
+
timestamp: now$1()
|
|
27
|
+
}));
|
|
28
|
+
} catch {}
|
|
29
|
+
}
|
|
30
|
+
setup() {
|
|
31
|
+
if (typeof window === "undefined" || typeof window.addEventListener === "undefined") return () => {};
|
|
32
|
+
const handler = (event) => {
|
|
33
|
+
if (event.key !== this.name) return;
|
|
34
|
+
const message = JSON.parse(event.newValue ?? "{}");
|
|
35
|
+
if (message?.event !== "session" || !message?.data) return;
|
|
36
|
+
this.listeners.forEach((listener) => listener(message));
|
|
37
|
+
};
|
|
38
|
+
window.addEventListener("storage", handler);
|
|
39
|
+
return () => {
|
|
40
|
+
window.removeEventListener("storage", handler);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
function getGlobalBroadcastChannel(name = "better-auth.message") {
|
|
45
|
+
if (!globalThis[kBroadcastChannel]) globalThis[kBroadcastChannel] = new WindowBroadcastChannel(name);
|
|
46
|
+
return globalThis[kBroadcastChannel];
|
|
47
|
+
}
|
|
48
|
+
const kFocusManager = Symbol.for("better-auth:focus-manager");
|
|
49
|
+
var WindowFocusManager = class {
|
|
50
|
+
listeners = /* @__PURE__ */ new Set();
|
|
51
|
+
subscribe(listener) {
|
|
52
|
+
this.listeners.add(listener);
|
|
53
|
+
return () => {
|
|
54
|
+
this.listeners.delete(listener);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
setFocused(focused) {
|
|
58
|
+
this.listeners.forEach((listener) => listener(focused));
|
|
59
|
+
}
|
|
60
|
+
setup() {
|
|
61
|
+
if (typeof window === "undefined" || typeof document === "undefined" || typeof window.addEventListener === "undefined") return () => {};
|
|
62
|
+
const visibilityHandler = () => {
|
|
63
|
+
if (document.visibilityState === "visible") this.setFocused(true);
|
|
64
|
+
};
|
|
65
|
+
document.addEventListener("visibilitychange", visibilityHandler, false);
|
|
66
|
+
return () => {
|
|
67
|
+
document.removeEventListener("visibilitychange", visibilityHandler, false);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
function getGlobalFocusManager() {
|
|
72
|
+
if (!globalThis[kFocusManager]) globalThis[kFocusManager] = new WindowFocusManager();
|
|
73
|
+
return globalThis[kFocusManager];
|
|
74
|
+
}
|
|
75
|
+
const kOnlineManager = Symbol.for("better-auth:online-manager");
|
|
76
|
+
var WindowOnlineManager = class {
|
|
77
|
+
listeners = /* @__PURE__ */ new Set();
|
|
78
|
+
isOnline = typeof navigator !== "undefined" ? navigator.onLine : true;
|
|
79
|
+
subscribe(listener) {
|
|
80
|
+
this.listeners.add(listener);
|
|
81
|
+
return () => {
|
|
82
|
+
this.listeners.delete(listener);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
setOnline(online) {
|
|
86
|
+
this.isOnline = online;
|
|
87
|
+
this.listeners.forEach((listener) => listener(online));
|
|
88
|
+
}
|
|
89
|
+
setup() {
|
|
90
|
+
if (typeof window === "undefined" || typeof window.addEventListener === "undefined") return () => {};
|
|
91
|
+
const onOnline = () => this.setOnline(true);
|
|
92
|
+
const onOffline = () => this.setOnline(false);
|
|
93
|
+
window.addEventListener("online", onOnline, false);
|
|
94
|
+
window.addEventListener("offline", onOffline, false);
|
|
95
|
+
return () => {
|
|
96
|
+
window.removeEventListener("online", onOnline, false);
|
|
97
|
+
window.removeEventListener("offline", onOffline, false);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
function getGlobalOnlineManager() {
|
|
102
|
+
if (!globalThis[kOnlineManager]) globalThis[kOnlineManager] = new WindowOnlineManager();
|
|
103
|
+
return globalThis[kOnlineManager];
|
|
104
|
+
}
|
|
105
|
+
const isServer = () => typeof window === "undefined";
|
|
106
|
+
const useAuthQuery = (initializedAtom, path, $fetch, options) => {
|
|
107
|
+
const value = atom({
|
|
108
|
+
data: null,
|
|
109
|
+
error: null,
|
|
110
|
+
isPending: true,
|
|
111
|
+
isRefetching: false,
|
|
112
|
+
refetch: (queryParams) => fn(queryParams)
|
|
113
|
+
});
|
|
114
|
+
const fn = async (queryParams) => {
|
|
115
|
+
return new Promise((resolve) => {
|
|
116
|
+
const opts = typeof options === "function" ? options({
|
|
117
|
+
data: value.get().data,
|
|
118
|
+
error: value.get().error,
|
|
119
|
+
isPending: value.get().isPending
|
|
120
|
+
}) : options;
|
|
121
|
+
$fetch(path, {
|
|
122
|
+
...opts,
|
|
123
|
+
query: {
|
|
124
|
+
...opts?.query,
|
|
125
|
+
...queryParams?.query
|
|
126
|
+
},
|
|
127
|
+
async onSuccess(context) {
|
|
128
|
+
value.set({
|
|
129
|
+
data: context.data,
|
|
130
|
+
error: null,
|
|
131
|
+
isPending: false,
|
|
132
|
+
isRefetching: false,
|
|
133
|
+
refetch: value.value.refetch
|
|
134
|
+
});
|
|
135
|
+
await opts?.onSuccess?.(context);
|
|
136
|
+
},
|
|
137
|
+
async onError(context) {
|
|
138
|
+
const { request } = context;
|
|
139
|
+
const retryAttempts = typeof request.retry === "number" ? request.retry : request.retry?.attempts;
|
|
140
|
+
const retryAttempt = request.retryAttempt || 0;
|
|
141
|
+
if (retryAttempts && retryAttempt < retryAttempts) return;
|
|
142
|
+
value.set({
|
|
143
|
+
error: context.error,
|
|
144
|
+
data: null,
|
|
145
|
+
isPending: false,
|
|
146
|
+
isRefetching: false,
|
|
147
|
+
refetch: value.value.refetch
|
|
148
|
+
});
|
|
149
|
+
await opts?.onError?.(context);
|
|
150
|
+
},
|
|
151
|
+
async onRequest(context) {
|
|
152
|
+
const currentValue = value.get();
|
|
153
|
+
value.set({
|
|
154
|
+
isPending: currentValue.data === null,
|
|
155
|
+
data: currentValue.data,
|
|
156
|
+
error: null,
|
|
157
|
+
isRefetching: true,
|
|
158
|
+
refetch: value.value.refetch
|
|
159
|
+
});
|
|
160
|
+
await opts?.onRequest?.(context);
|
|
161
|
+
}
|
|
162
|
+
}).catch((error) => {
|
|
163
|
+
value.set({
|
|
164
|
+
error,
|
|
165
|
+
data: null,
|
|
166
|
+
isPending: false,
|
|
167
|
+
isRefetching: false,
|
|
168
|
+
refetch: value.value.refetch
|
|
169
|
+
});
|
|
170
|
+
}).finally(() => {
|
|
171
|
+
resolve(void 0);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
initializedAtom = Array.isArray(initializedAtom) ? initializedAtom : [initializedAtom];
|
|
176
|
+
let isMounted = false;
|
|
177
|
+
for (const initAtom of initializedAtom) initAtom.subscribe(async () => {
|
|
178
|
+
if (isServer()) return;
|
|
179
|
+
if (isMounted) await fn();
|
|
180
|
+
else onMount(value, () => {
|
|
181
|
+
const timeoutId = setTimeout(async () => {
|
|
182
|
+
if (!isMounted) {
|
|
183
|
+
await fn();
|
|
184
|
+
isMounted = true;
|
|
185
|
+
}
|
|
186
|
+
}, 0);
|
|
187
|
+
return () => {
|
|
188
|
+
value.off();
|
|
189
|
+
initAtom.off();
|
|
190
|
+
clearTimeout(timeoutId);
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
return value;
|
|
195
|
+
};
|
|
196
|
+
const now = () => Math.floor(Date.now() / 1e3);
|
|
197
|
+
/**
|
|
198
|
+
* Rate limit: don't refetch on focus if a session request was made within this many seconds
|
|
199
|
+
*/
|
|
200
|
+
const FOCUS_REFETCH_RATE_LIMIT_SECONDS = 5;
|
|
201
|
+
function createSessionRefreshManager(opts) {
|
|
202
|
+
const { sessionAtom, sessionSignal, $fetch, options = {} } = opts;
|
|
203
|
+
const refetchInterval = options.sessionOptions?.refetchInterval ?? 0;
|
|
204
|
+
const refetchOnWindowFocus = options.sessionOptions?.refetchOnWindowFocus ?? true;
|
|
205
|
+
const refetchWhenOffline = options.sessionOptions?.refetchWhenOffline ?? false;
|
|
206
|
+
const state = {
|
|
207
|
+
lastSync: 0,
|
|
208
|
+
lastSessionRequest: 0,
|
|
209
|
+
cachedSession: void 0
|
|
210
|
+
};
|
|
211
|
+
const shouldRefetch = () => {
|
|
212
|
+
return refetchWhenOffline || getGlobalOnlineManager().isOnline;
|
|
213
|
+
};
|
|
214
|
+
const triggerRefetch = (event) => {
|
|
215
|
+
if (!shouldRefetch()) return;
|
|
216
|
+
if (event?.event === "storage") {
|
|
217
|
+
state.lastSync = now();
|
|
218
|
+
sessionSignal.set(!sessionSignal.get());
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const currentSession = sessionAtom.get();
|
|
222
|
+
if (event?.event === "poll") {
|
|
223
|
+
state.lastSessionRequest = now();
|
|
224
|
+
$fetch("/get-session").then((res) => {
|
|
225
|
+
sessionAtom.set({
|
|
226
|
+
...currentSession,
|
|
227
|
+
data: res.data,
|
|
228
|
+
error: res.error || null
|
|
229
|
+
});
|
|
230
|
+
state.lastSync = now();
|
|
231
|
+
sessionSignal.set(!sessionSignal.get());
|
|
232
|
+
}).catch(() => {});
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (event?.event === "visibilitychange") {
|
|
236
|
+
if (now() - state.lastSessionRequest < FOCUS_REFETCH_RATE_LIMIT_SECONDS && currentSession?.data !== null && currentSession?.data !== void 0) return;
|
|
237
|
+
}
|
|
238
|
+
if (currentSession?.data === null || currentSession?.data === void 0 || event?.event === "visibilitychange") {
|
|
239
|
+
if (event?.event === "visibilitychange") state.lastSessionRequest = now();
|
|
240
|
+
state.lastSync = now();
|
|
241
|
+
sessionSignal.set(!sessionSignal.get());
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
const broadcastSessionUpdate = (trigger) => {
|
|
245
|
+
getGlobalBroadcastChannel().post({
|
|
246
|
+
event: "session",
|
|
247
|
+
data: { trigger },
|
|
248
|
+
clientId: Math.random().toString(36).substring(7)
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
const setupPolling = () => {
|
|
252
|
+
if (refetchInterval && refetchInterval > 0) state.pollInterval = setInterval(() => {
|
|
253
|
+
if (sessionAtom.get()?.data) triggerRefetch({ event: "poll" });
|
|
254
|
+
}, refetchInterval * 1e3);
|
|
255
|
+
};
|
|
256
|
+
const setupBroadcast = () => {
|
|
257
|
+
state.unsubscribeBroadcast = getGlobalBroadcastChannel().subscribe(() => {
|
|
258
|
+
triggerRefetch({ event: "storage" });
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
const setupFocusRefetch = () => {
|
|
262
|
+
if (!refetchOnWindowFocus) return;
|
|
263
|
+
state.unsubscribeFocus = getGlobalFocusManager().subscribe(() => {
|
|
264
|
+
triggerRefetch({ event: "visibilitychange" });
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
const setupOnlineRefetch = () => {
|
|
268
|
+
state.unsubscribeOnline = getGlobalOnlineManager().subscribe((online) => {
|
|
269
|
+
if (online) triggerRefetch({ event: "visibilitychange" });
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
const init = () => {
|
|
273
|
+
setupPolling();
|
|
274
|
+
setupBroadcast();
|
|
275
|
+
setupFocusRefetch();
|
|
276
|
+
setupOnlineRefetch();
|
|
277
|
+
getGlobalBroadcastChannel().setup();
|
|
278
|
+
getGlobalFocusManager().setup();
|
|
279
|
+
getGlobalOnlineManager().setup();
|
|
280
|
+
};
|
|
281
|
+
const cleanup = () => {
|
|
282
|
+
if (state.pollInterval) {
|
|
283
|
+
clearInterval(state.pollInterval);
|
|
284
|
+
state.pollInterval = void 0;
|
|
285
|
+
}
|
|
286
|
+
if (state.unsubscribeBroadcast) {
|
|
287
|
+
state.unsubscribeBroadcast();
|
|
288
|
+
state.unsubscribeBroadcast = void 0;
|
|
289
|
+
}
|
|
290
|
+
if (state.unsubscribeFocus) {
|
|
291
|
+
state.unsubscribeFocus();
|
|
292
|
+
state.unsubscribeFocus = void 0;
|
|
293
|
+
}
|
|
294
|
+
if (state.unsubscribeOnline) {
|
|
295
|
+
state.unsubscribeOnline();
|
|
296
|
+
state.unsubscribeOnline = void 0;
|
|
297
|
+
}
|
|
298
|
+
state.lastSync = 0;
|
|
299
|
+
state.lastSessionRequest = 0;
|
|
300
|
+
state.cachedSession = void 0;
|
|
301
|
+
};
|
|
302
|
+
return {
|
|
303
|
+
init,
|
|
304
|
+
cleanup,
|
|
305
|
+
triggerRefetch,
|
|
306
|
+
broadcastSessionUpdate
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
const redirectPlugin = {
|
|
310
|
+
id: "redirect",
|
|
311
|
+
name: "Redirect",
|
|
312
|
+
hooks: { onSuccess(context) {
|
|
313
|
+
if (context.data?.url && context.data?.redirect) {
|
|
314
|
+
if (typeof window !== "undefined" && window.location) {
|
|
315
|
+
if (window.location) try {
|
|
316
|
+
window.location.href = context.data.url;
|
|
317
|
+
} catch {}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
} }
|
|
321
|
+
};
|
|
322
|
+
const userAgentPlugin = {
|
|
323
|
+
id: "user-agent",
|
|
324
|
+
name: "UserAgent",
|
|
325
|
+
hooks: { onRequest(context) {
|
|
326
|
+
context.headers.append("user-agent", "better-auth");
|
|
327
|
+
} }
|
|
328
|
+
};
|
|
329
|
+
function getSessionAtom($fetch, options) {
|
|
330
|
+
const $signal = atom(false);
|
|
331
|
+
const session = useAuthQuery($signal, "/get-session", $fetch, { method: "GET" });
|
|
332
|
+
onMount(session, () => {
|
|
333
|
+
const refreshManager = createSessionRefreshManager({
|
|
334
|
+
sessionAtom: session,
|
|
335
|
+
sessionSignal: $signal,
|
|
336
|
+
$fetch,
|
|
337
|
+
options
|
|
338
|
+
});
|
|
339
|
+
refreshManager.init();
|
|
340
|
+
return () => {
|
|
341
|
+
refreshManager.cleanup();
|
|
342
|
+
};
|
|
343
|
+
});
|
|
344
|
+
return {
|
|
345
|
+
session,
|
|
346
|
+
$sessionSignal: $signal
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
const getClientConfig = (options, loadEnv) => {
|
|
350
|
+
const isCredentialsSupported = "credentials" in Request.prototype;
|
|
351
|
+
const baseURL = getBaseURL(options?.baseURL, options?.basePath, void 0, loadEnv) ?? "/api/auth";
|
|
352
|
+
const pluginsFetchPlugins = options?.plugins?.flatMap((plugin) => plugin.fetchPlugins).filter((pl) => pl !== void 0) || [];
|
|
353
|
+
const lifeCyclePlugin = {
|
|
354
|
+
id: "lifecycle-hooks",
|
|
355
|
+
name: "lifecycle-hooks",
|
|
356
|
+
hooks: {
|
|
357
|
+
onSuccess: options?.fetchOptions?.onSuccess,
|
|
358
|
+
onError: options?.fetchOptions?.onError,
|
|
359
|
+
onRequest: options?.fetchOptions?.onRequest,
|
|
360
|
+
onResponse: options?.fetchOptions?.onResponse
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
const { onSuccess, onError, onRequest, onResponse, ...restOfFetchOptions } = options?.fetchOptions || {};
|
|
364
|
+
const $fetch = createFetch({
|
|
365
|
+
baseURL,
|
|
366
|
+
...isCredentialsSupported ? { credentials: "include" } : {},
|
|
367
|
+
method: "GET",
|
|
368
|
+
jsonParser(text) {
|
|
369
|
+
if (!text) return null;
|
|
370
|
+
return parseJSON(text, { strict: false });
|
|
371
|
+
},
|
|
372
|
+
customFetchImpl: fetch,
|
|
373
|
+
...restOfFetchOptions,
|
|
374
|
+
plugins: [
|
|
375
|
+
lifeCyclePlugin,
|
|
376
|
+
...restOfFetchOptions.plugins || [],
|
|
377
|
+
...options?.disableDefaultFetchPlugins ? [] : [userAgentPlugin, redirectPlugin],
|
|
378
|
+
...pluginsFetchPlugins
|
|
379
|
+
]
|
|
380
|
+
});
|
|
381
|
+
const { $sessionSignal, session } = getSessionAtom($fetch, options);
|
|
382
|
+
const plugins = options?.plugins || [];
|
|
383
|
+
let pluginsActions = {};
|
|
384
|
+
let pluginsAtoms = {
|
|
385
|
+
$sessionSignal,
|
|
386
|
+
session
|
|
387
|
+
};
|
|
388
|
+
let pluginPathMethods = {
|
|
389
|
+
"/sign-out": "POST",
|
|
390
|
+
"/revoke-sessions": "POST",
|
|
391
|
+
"/revoke-other-sessions": "POST",
|
|
392
|
+
"/delete-user": "POST"
|
|
393
|
+
};
|
|
394
|
+
const atomListeners = [{
|
|
395
|
+
signal: "$sessionSignal",
|
|
396
|
+
matcher(path) {
|
|
397
|
+
return path === "/sign-out" || path === "/update-user" || path === "/sign-up/email" || path === "/sign-in/email" || path === "/delete-user" || path === "/verify-email" || path === "/revoke-sessions" || path === "/revoke-session" || path === "/change-email";
|
|
398
|
+
}
|
|
399
|
+
}];
|
|
400
|
+
for (const plugin of plugins) {
|
|
401
|
+
if (plugin.getAtoms) Object.assign(pluginsAtoms, plugin.getAtoms?.($fetch));
|
|
402
|
+
if (plugin.pathMethods) Object.assign(pluginPathMethods, plugin.pathMethods);
|
|
403
|
+
if (plugin.atomListeners) atomListeners.push(...plugin.atomListeners);
|
|
404
|
+
}
|
|
405
|
+
const $store = {
|
|
406
|
+
notify: (signal) => {
|
|
407
|
+
pluginsAtoms[signal].set(!pluginsAtoms[signal].get());
|
|
408
|
+
},
|
|
409
|
+
listen: (signal, listener) => {
|
|
410
|
+
pluginsAtoms[signal].subscribe(listener);
|
|
411
|
+
},
|
|
412
|
+
atoms: pluginsAtoms
|
|
413
|
+
};
|
|
414
|
+
for (const plugin of plugins) if (plugin.getActions) Object.assign(pluginsActions, plugin.getActions?.($fetch, $store, options));
|
|
415
|
+
return {
|
|
416
|
+
get baseURL() {
|
|
417
|
+
return baseURL;
|
|
418
|
+
},
|
|
419
|
+
pluginsActions,
|
|
420
|
+
pluginsAtoms,
|
|
421
|
+
pluginPathMethods,
|
|
422
|
+
atomListeners,
|
|
423
|
+
$fetch,
|
|
424
|
+
$store
|
|
425
|
+
};
|
|
426
|
+
};
|
|
427
|
+
function isAtom(value) {
|
|
428
|
+
return typeof value === "object" && value !== null && "get" in value && typeof value.get === "function" && "lc" in value && typeof value.lc === "number";
|
|
429
|
+
}
|
|
430
|
+
function getMethod(path, knownPathMethods, args) {
|
|
431
|
+
const method = knownPathMethods[path];
|
|
432
|
+
const { fetchOptions, query, ...body } = args || {};
|
|
433
|
+
if (method) return method;
|
|
434
|
+
if (fetchOptions?.method) return fetchOptions.method;
|
|
435
|
+
if (body && Object.keys(body).length > 0) return "POST";
|
|
436
|
+
return "GET";
|
|
437
|
+
}
|
|
438
|
+
function createDynamicPathProxy(routes, client, knownPathMethods, atoms, atomListeners) {
|
|
439
|
+
function createProxy(path = []) {
|
|
440
|
+
return new Proxy(function() {}, {
|
|
441
|
+
get(_, prop) {
|
|
442
|
+
if (typeof prop !== "string") return;
|
|
443
|
+
if (prop === "then" || prop === "catch" || prop === "finally") return;
|
|
444
|
+
const fullPath = [...path, prop];
|
|
445
|
+
let current = routes;
|
|
446
|
+
for (const segment of fullPath) if (current && typeof current === "object" && segment in current) current = current[segment];
|
|
447
|
+
else {
|
|
448
|
+
current = void 0;
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
if (typeof current === "function") return current;
|
|
452
|
+
if (isAtom(current)) return current;
|
|
453
|
+
return createProxy(fullPath);
|
|
454
|
+
},
|
|
455
|
+
apply: async (_, __, args) => {
|
|
456
|
+
const routePath = "/" + path.map((segment) => segment.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)).join("/");
|
|
457
|
+
const arg = args[0] || {};
|
|
458
|
+
const fetchOptions = args[1] || {};
|
|
459
|
+
const { query, fetchOptions: argFetchOptions, ...body } = arg;
|
|
460
|
+
const options = {
|
|
461
|
+
...fetchOptions,
|
|
462
|
+
...argFetchOptions
|
|
463
|
+
};
|
|
464
|
+
const method = getMethod(routePath, knownPathMethods, arg);
|
|
465
|
+
return await client(routePath, {
|
|
466
|
+
...options,
|
|
467
|
+
body: method === "GET" ? void 0 : {
|
|
468
|
+
...body,
|
|
469
|
+
...options?.body || {}
|
|
470
|
+
},
|
|
471
|
+
query: query || options?.query,
|
|
472
|
+
method,
|
|
473
|
+
async onSuccess(context) {
|
|
474
|
+
await options?.onSuccess?.(context);
|
|
475
|
+
if (!atomListeners || options.disableSignal) return;
|
|
476
|
+
/**
|
|
477
|
+
* We trigger listeners
|
|
478
|
+
*/
|
|
479
|
+
const matches = atomListeners.filter((s) => s.matcher(routePath));
|
|
480
|
+
if (!matches.length) return;
|
|
481
|
+
for (const match of matches) {
|
|
482
|
+
const signal = atoms[match.signal];
|
|
483
|
+
if (!signal) return;
|
|
484
|
+
/**
|
|
485
|
+
* To avoid race conditions we set the signal in a setTimeout
|
|
486
|
+
*/
|
|
487
|
+
const val = signal.get();
|
|
488
|
+
setTimeout(() => {
|
|
489
|
+
signal.set(!val);
|
|
490
|
+
}, 10);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
return createProxy();
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
//#endregion
|
|
501
|
+
//#region ../better-auth/dist/client/react/index.mjs
|
|
502
|
+
/**
|
|
503
|
+
* Subscribe to store changes and get store's value.
|
|
504
|
+
*
|
|
505
|
+
* Can be used with store builder too.
|
|
506
|
+
*
|
|
507
|
+
* ```js
|
|
508
|
+
* import { useStore } from 'nanostores/react'
|
|
509
|
+
*
|
|
510
|
+
* import { router } from '../store/router'
|
|
511
|
+
*
|
|
512
|
+
* export const Layout = () => {
|
|
513
|
+
* let page = useStore(router)
|
|
514
|
+
* if (page.route === 'home') {
|
|
515
|
+
* return <HomePage />
|
|
516
|
+
* } else {
|
|
517
|
+
* return <Error404 />
|
|
518
|
+
* }
|
|
519
|
+
* }
|
|
520
|
+
* ```
|
|
521
|
+
*
|
|
522
|
+
* @param store Store instance.
|
|
523
|
+
* @returns Store value.
|
|
524
|
+
*/
|
|
525
|
+
function useStore(store, options = {}) {
|
|
526
|
+
let snapshotRef = useRef(store.get());
|
|
527
|
+
const { keys, deps = [store, keys] } = options;
|
|
528
|
+
let subscribe = useCallback((onChange) => {
|
|
529
|
+
const emitChange = (value) => {
|
|
530
|
+
if (snapshotRef.current === value) return;
|
|
531
|
+
snapshotRef.current = value;
|
|
532
|
+
onChange();
|
|
533
|
+
};
|
|
534
|
+
emitChange(store.value);
|
|
535
|
+
if (keys?.length) return listenKeys(store, keys, emitChange);
|
|
536
|
+
return store.listen(emitChange);
|
|
537
|
+
}, deps);
|
|
538
|
+
let get = () => snapshotRef.current;
|
|
539
|
+
return useSyncExternalStore(subscribe, get, get);
|
|
540
|
+
}
|
|
541
|
+
function getAtomKey(str) {
|
|
542
|
+
return `use${capitalizeFirstLetter(str)}`;
|
|
543
|
+
}
|
|
544
|
+
function capitalizeFirstLetter(str) {
|
|
545
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
546
|
+
}
|
|
547
|
+
function createAuthClient(options) {
|
|
548
|
+
const { pluginPathMethods, pluginsActions, pluginsAtoms, $fetch, $store, atomListeners } = getClientConfig(options);
|
|
549
|
+
let resolvedHooks = {};
|
|
550
|
+
for (const [key, value] of Object.entries(pluginsAtoms)) resolvedHooks[getAtomKey(key)] = () => useStore(value);
|
|
551
|
+
return createDynamicPathProxy({
|
|
552
|
+
...pluginsActions,
|
|
553
|
+
...resolvedHooks,
|
|
554
|
+
$fetch,
|
|
555
|
+
$store
|
|
556
|
+
}, $fetch, pluginPathMethods, pluginsAtoms, atomListeners);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
//#endregion
|
|
560
|
+
export { useAuthQuery as i, createAuthClient as n, useStore as r, capitalizeFirstLetter as t };
|
package/dist/react.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "better-auth/react";
|
package/dist/react.mjs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import "./env-DwlNAN_D-C1zHd0cf-Cdlw8sNp.mjs";
|
|
2
|
+
import "./dist-CygcgJYk.mjs";
|
|
3
|
+
import "./parser-bL7W2mQ0-YdTgjtji.mjs";
|
|
4
|
+
import { n as createAuthClient, r as useStore, t as capitalizeFirstLetter } from "./react--VZQu7s1.mjs";
|
|
5
|
+
|
|
6
|
+
export { capitalizeFirstLetter, createAuthClient, useStore };
|
package/dist/server.mjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { n as db } from "./db-BVXTgOd3.mjs";
|
|
2
|
+
import "./json-oFuWgANh-O1U6k3bL.mjs";
|
|
3
|
+
import "./env-DwlNAN_D-C1zHd0cf-Cdlw8sNp.mjs";
|
|
4
|
+
import "./verify-CN5Qc0e-.mjs";
|
|
5
|
+
import "./social-providers-DNfE9Ak7-Be5zMAEe.mjs";
|
|
6
|
+
import "./plugins-BNFht2HW.mjs";
|
|
7
|
+
import "./esm-C5TuvtGn.mjs";
|
|
8
|
+
import "./dialect-C6_pK3V9-CPJHWkYR.mjs";
|
|
9
|
+
import "./dist-CygcgJYk.mjs";
|
|
10
|
+
import "./misc-CbURQDlR-sLtUwwQY.mjs";
|
|
11
|
+
import "./parser-bL7W2mQ0-YdTgjtji.mjs";
|
|
12
|
+
import "./client--1_AEBPu-8Ae9icC9.mjs";
|
|
13
|
+
import "./db-schema.final-DWleoQm0.mjs";
|
|
14
|
+
import "./adapter-factory-BTRALCLD-kJBwe70v.mjs";
|
|
15
|
+
import { t as auth } from "./better-auth-CqfhQJYE.mjs";
|
|
16
|
+
import "dotenv/config";
|
|
17
|
+
import { cors } from "@elysiajs/cors";
|
|
18
|
+
import { jwt } from "@elysiajs/jwt";
|
|
19
|
+
import openapi from "@elysiajs/openapi";
|
|
20
|
+
import { migrate } from "drizzle-orm/node-postgres/migrator";
|
|
21
|
+
import { Elysia } from "elysia";
|
|
22
|
+
|
|
23
|
+
//#region src/server.ts
|
|
24
|
+
await migrate(db, {
|
|
25
|
+
migrationsFolder: "./drizzle",
|
|
26
|
+
migrationsSchema: "enterprise",
|
|
27
|
+
migrationsTable: "_migrations"
|
|
28
|
+
});
|
|
29
|
+
await import("./init-D8lwWc90.mjs");
|
|
30
|
+
const app = new Elysia().use(openapi({ path: "/openapi" })).use(jwt({
|
|
31
|
+
name: "jwt",
|
|
32
|
+
secret: "Fischl von Luftschloss Narfidort"
|
|
33
|
+
})).use(cors()).all("/api/auth/*", (context) => {
|
|
34
|
+
if (["POST", "GET"].includes(context.request.method)) return auth.handler(context.request);
|
|
35
|
+
else throw new Error("Method not allowed");
|
|
36
|
+
}).get("/", () => "Hello Elysia");
|
|
37
|
+
var server_default = {
|
|
38
|
+
fetch: app.fetch.bind(app),
|
|
39
|
+
port: 3001
|
|
40
|
+
};
|
|
41
|
+
console.log("Server is running on port 3001");
|
|
42
|
+
console.log("Playground: http://localhost:3001/api/auth/reference");
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { server_default as default };
|