better-auth 0.0.8-beta.2 → 0.0.8-beta.21
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/access.d.ts +3 -4
- package/dist/access.js +3 -13
- package/dist/access.js.map +1 -1
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +36 -44
- package/dist/cli.js.map +1 -1
- package/dist/client/plugins.d.ts +97 -2407
- package/dist/client/plugins.js +143 -203
- package/dist/client/plugins.js.map +1 -1
- package/dist/client.d.ts +159 -1213
- package/dist/client.js +125 -527
- package/dist/client.js.map +1 -1
- package/dist/{helper-B5_2Vzba.d.ts → helper-D8dhRz72.d.ts} +1 -4
- package/dist/{index-Dg4eEXZW.d.ts → index-B9jOjqnF.d.ts} +1 -1
- package/dist/{schema-BOszzrbQ.d.ts → index-CcxejJTH.d.ts} +172 -142
- package/dist/{client-CaF9eUcv.d.ts → index-Dwhjsk4l.d.ts} +2014 -1971
- package/dist/index.d.ts +1124 -6
- package/dist/index.js +737 -707
- package/dist/index.js.map +1 -1
- package/dist/internal-adapter-CVKQ4XR9.d.ts +637 -0
- package/dist/next-js.d.ts +17 -7
- package/dist/next-js.js +20 -3
- package/dist/next-js.js.map +1 -1
- package/dist/plugins.d.ts +12 -883
- package/dist/plugins.js +743 -679
- package/dist/plugins.js.map +1 -1
- package/dist/react.d.ts +312 -12
- package/dist/react.js +138 -148
- package/dist/react.js.map +1 -1
- package/dist/social.d.ts +2 -2
- package/dist/social.js +179 -151
- package/dist/social.js.map +1 -1
- package/dist/solid-start.d.ts +7 -6
- package/dist/solid-start.js +3 -3
- package/dist/solid-start.js.map +1 -1
- package/dist/solid.d.ts +91 -2713
- package/dist/solid.js +130 -139
- package/dist/solid.js.map +1 -1
- package/dist/{statement-COylZd3J.d.ts → statement-D6SPoYOh.d.ts} +7 -7
- package/dist/svelte-kit.d.ts +6 -5
- package/dist/svelte-kit.js +10 -9
- package/dist/svelte-kit.js.map +1 -1
- package/dist/svelte.d.ts +89 -2713
- package/dist/svelte.js +124 -138
- package/dist/svelte.js.map +1 -1
- package/dist/types-D4WrjKeJ.d.ts +81 -0
- package/dist/types.d.ts +31 -5
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -1
- package/dist/vue.d.ts +313 -12
- package/dist/vue.js +131 -145
- package/dist/vue.js.map +1 -1
- package/package.json +8 -3
- package/dist/index-CGeV0d2g.d.ts +0 -1498
- package/dist/preact.d.ts +0 -8
- package/dist/preact.js +0 -291
- package/dist/preact.js.map +0 -1
- package/dist/type-tYx_kmry.d.ts +0 -5724
package/dist/react.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { createFetch } from "@better-fetch/fetch";
|
|
1
|
+
import { useStore } from '@nanostores/react';
|
|
2
|
+
import { createFetch, betterFetch } from '@better-fetch/fetch';
|
|
3
|
+
import { atom, computed, task } from 'nanostores';
|
|
4
|
+
import { useState, useEffect } from 'react';
|
|
6
5
|
|
|
7
|
-
// src/
|
|
8
|
-
var BetterAuthError = class extends Error {
|
|
9
|
-
constructor(message) {
|
|
10
|
-
super(message);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
6
|
+
// src/client/react.ts
|
|
13
7
|
|
|
14
8
|
// src/utils/base-url.ts
|
|
15
9
|
function checkHasPath(url) {
|
|
@@ -24,47 +18,43 @@ function checkHasPath(url) {
|
|
|
24
18
|
function withPath(url, path = "/api/auth") {
|
|
25
19
|
const hasPath = checkHasPath(url);
|
|
26
20
|
if (hasPath) {
|
|
27
|
-
return
|
|
28
|
-
baseURL: new URL(url).origin,
|
|
29
|
-
withPath: url
|
|
30
|
-
};
|
|
21
|
+
return url;
|
|
31
22
|
}
|
|
32
23
|
path = path.startsWith("/") ? path : `/${path}`;
|
|
33
|
-
return {
|
|
34
|
-
baseURL: url,
|
|
35
|
-
withPath: `${url}${path}`
|
|
36
|
-
};
|
|
24
|
+
return `${url}${path}`;
|
|
37
25
|
}
|
|
38
26
|
function getBaseURL(url, path) {
|
|
39
27
|
if (url) {
|
|
40
28
|
return withPath(url, path);
|
|
41
29
|
}
|
|
42
30
|
const env = typeof process !== "undefined" ? process.env : {};
|
|
43
|
-
const fromEnv = env.BETTER_AUTH_URL || env.
|
|
31
|
+
const fromEnv = env.BETTER_AUTH_URL || env.NEXT_PUBLIC_BETTER_AUTH_URL || env.PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_AUTH_URL;
|
|
44
32
|
if (fromEnv) {
|
|
45
33
|
return withPath(fromEnv, path);
|
|
46
34
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
baseURL: "http://localhost:3000",
|
|
51
|
-
withPath: "http://localhost:3000/api/auth"
|
|
52
|
-
};
|
|
35
|
+
if (typeof window !== "undefined") {
|
|
36
|
+
return withPath(window.location.origin, path);
|
|
53
37
|
}
|
|
54
|
-
|
|
55
|
-
"Could not infer baseURL from environment variables"
|
|
56
|
-
);
|
|
38
|
+
return void 0;
|
|
57
39
|
}
|
|
58
40
|
|
|
41
|
+
// src/error/better-auth-error.ts
|
|
42
|
+
var BetterAuthError = class extends Error {
|
|
43
|
+
constructor(message) {
|
|
44
|
+
super(message);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
59
48
|
// src/client/fetch-plugins.ts
|
|
60
|
-
import { betterFetch } from "@better-fetch/fetch";
|
|
61
49
|
var redirectPlugin = {
|
|
62
50
|
id: "redirect",
|
|
63
51
|
name: "Redirect",
|
|
64
52
|
hooks: {
|
|
65
53
|
onSuccess(context) {
|
|
66
54
|
if (context.data?.url && context.data?.redirect) {
|
|
67
|
-
window
|
|
55
|
+
if (typeof window !== "undefined") {
|
|
56
|
+
window.location.href = context.data.url;
|
|
57
|
+
}
|
|
68
58
|
}
|
|
69
59
|
}
|
|
70
60
|
}
|
|
@@ -87,6 +77,17 @@ var csrfPlugin = {
|
|
|
87
77
|
id: "csrf",
|
|
88
78
|
name: "CSRF Check",
|
|
89
79
|
async init(url, options) {
|
|
80
|
+
if (typeof window !== "undefined") {
|
|
81
|
+
const isTheSameOrigin = new URL(options?.baseURL || url).origin === window.location.origin;
|
|
82
|
+
if (isTheSameOrigin) {
|
|
83
|
+
return { url, options };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (!options?.baseURL) {
|
|
87
|
+
throw new BetterAuthError(
|
|
88
|
+
"API Base URL on the auth client isn't configured. Please pass it directly to the client `baseURL`"
|
|
89
|
+
);
|
|
90
|
+
}
|
|
90
91
|
if (options?.method !== "GET") {
|
|
91
92
|
options = options || {};
|
|
92
93
|
const { data, error } = await betterFetch("/csrf", {
|
|
@@ -94,7 +95,8 @@ var csrfPlugin = {
|
|
|
94
95
|
baseURL: options.baseURL,
|
|
95
96
|
plugins: [],
|
|
96
97
|
method: "GET",
|
|
97
|
-
credentials: "include"
|
|
98
|
+
credentials: "include",
|
|
99
|
+
customFetchImpl: options.customFetchImpl
|
|
98
100
|
});
|
|
99
101
|
if (error?.status === 404) {
|
|
100
102
|
throw new BetterAuthError(
|
|
@@ -114,6 +116,61 @@ var csrfPlugin = {
|
|
|
114
116
|
}
|
|
115
117
|
};
|
|
116
118
|
|
|
119
|
+
// src/client/config.ts
|
|
120
|
+
var getClientConfig = (options) => {
|
|
121
|
+
const $fetch = createFetch({
|
|
122
|
+
baseURL: getBaseURL(options?.fetchOptions?.baseURL || options?.baseURL),
|
|
123
|
+
...options?.fetchOptions,
|
|
124
|
+
plugins: [
|
|
125
|
+
csrfPlugin,
|
|
126
|
+
redirectPlugin,
|
|
127
|
+
addCurrentURL,
|
|
128
|
+
...options?.fetchOptions?.plugins || [],
|
|
129
|
+
...options?.plugins?.flatMap((plugin) => plugin.fetchPlugins).filter((pl) => pl !== void 0) || []
|
|
130
|
+
]
|
|
131
|
+
});
|
|
132
|
+
const plugins = options?.plugins || [];
|
|
133
|
+
let pluginsActions = {};
|
|
134
|
+
let pluginsAtoms = {};
|
|
135
|
+
let pluginPathMethods = {
|
|
136
|
+
"/sign-out": "POST"
|
|
137
|
+
};
|
|
138
|
+
const atomListeners = [
|
|
139
|
+
{
|
|
140
|
+
signal: "_sessionSignal",
|
|
141
|
+
matcher(path) {
|
|
142
|
+
return path === "/sign-out" || path === "sign-up/email";
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
];
|
|
146
|
+
for (const plugin of plugins) {
|
|
147
|
+
if (plugin.getActions) {
|
|
148
|
+
Object.assign(pluginsActions, plugin.getActions?.($fetch));
|
|
149
|
+
}
|
|
150
|
+
if (plugin.getAtoms) {
|
|
151
|
+
Object.assign(pluginsAtoms, plugin.getAtoms?.($fetch));
|
|
152
|
+
}
|
|
153
|
+
if (plugin.pathMethods) {
|
|
154
|
+
Object.assign(pluginPathMethods, plugin.pathMethods);
|
|
155
|
+
}
|
|
156
|
+
if (plugin.atomListeners) {
|
|
157
|
+
atomListeners.push(...plugin.atomListeners);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
pluginsActions,
|
|
162
|
+
pluginsAtoms,
|
|
163
|
+
pluginPathMethods,
|
|
164
|
+
atomListeners,
|
|
165
|
+
$fetch
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// src/utils/misc.ts
|
|
170
|
+
function capitalizeFirstLetter(str) {
|
|
171
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
172
|
+
}
|
|
173
|
+
|
|
117
174
|
// src/client/proxy.ts
|
|
118
175
|
function getMethod(path, knownPathMethods, args) {
|
|
119
176
|
const method = knownPathMethods[path];
|
|
@@ -129,7 +186,7 @@ function getMethod(path, knownPathMethods, args) {
|
|
|
129
186
|
}
|
|
130
187
|
return "GET";
|
|
131
188
|
}
|
|
132
|
-
function createDynamicPathProxy(routes, client, knownPathMethods,
|
|
189
|
+
function createDynamicPathProxy(routes, client, knownPathMethods, atoms, atomListeners) {
|
|
133
190
|
function createProxy(path = []) {
|
|
134
191
|
return new Proxy(function() {
|
|
135
192
|
}, {
|
|
@@ -158,16 +215,21 @@ function createDynamicPathProxy(routes, client, knownPathMethods, $signal, $sign
|
|
|
158
215
|
const { query, options, ...body } = arg;
|
|
159
216
|
return await client(routePath, {
|
|
160
217
|
...options,
|
|
161
|
-
body: method === "GET" ? void 0 :
|
|
218
|
+
body: method === "GET" ? void 0 : {
|
|
219
|
+
...body,
|
|
220
|
+
...options?.body || {}
|
|
221
|
+
},
|
|
162
222
|
query,
|
|
163
223
|
method,
|
|
164
224
|
async onSuccess(context) {
|
|
165
|
-
const signal = $signal?.find((s) => s.matcher(routePath));
|
|
166
|
-
if (!signal) return;
|
|
167
|
-
const signalAtom = $signals?.[signal.atom];
|
|
168
|
-
if (!signalAtom) return;
|
|
169
|
-
signalAtom.set(!signalAtom.get());
|
|
170
225
|
await options?.onSuccess?.(context);
|
|
226
|
+
const matches = atomListeners?.find((s) => s.matcher(routePath));
|
|
227
|
+
if (!matches) return;
|
|
228
|
+
const signal = atoms[matches.signal];
|
|
229
|
+
if (!signal) return;
|
|
230
|
+
setTimeout(() => {
|
|
231
|
+
signal.set(!signal.get());
|
|
232
|
+
}, 0);
|
|
171
233
|
}
|
|
172
234
|
});
|
|
173
235
|
}
|
|
@@ -175,9 +237,6 @@ function createDynamicPathProxy(routes, client, knownPathMethods, $signal, $sign
|
|
|
175
237
|
}
|
|
176
238
|
return createProxy();
|
|
177
239
|
}
|
|
178
|
-
|
|
179
|
-
// src/client/session-atom.ts
|
|
180
|
-
import { atom, computed, task } from "nanostores";
|
|
181
240
|
function getSessionAtom(client) {
|
|
182
241
|
const $signal = atom(false);
|
|
183
242
|
const $session = computed(
|
|
@@ -190,122 +249,53 @@ function getSessionAtom(client) {
|
|
|
190
249
|
return session.data;
|
|
191
250
|
})
|
|
192
251
|
);
|
|
193
|
-
return { $session,
|
|
252
|
+
return { $session, _sessionSignal: $signal };
|
|
194
253
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
for (const plugin of options?.authPlugins || []) {
|
|
220
|
-
const pl = plugin($fetch);
|
|
221
|
-
if (pl.authProxySignal) {
|
|
222
|
-
pluginProxySignals.push(...pl.authProxySignal);
|
|
223
|
-
}
|
|
224
|
-
if (pl.actions) {
|
|
225
|
-
pluginsActions = {
|
|
226
|
-
...pluginsActions,
|
|
227
|
-
...pl.actions
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
if (pl.signals) {
|
|
231
|
-
pluginSignals = {
|
|
232
|
-
...pluginSignals,
|
|
233
|
-
...pl.signals
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
if (pl.pathMethods) {
|
|
237
|
-
pluginPathMethods = {
|
|
238
|
-
...pluginPathMethods,
|
|
239
|
-
...pl.pathMethods
|
|
240
|
-
};
|
|
254
|
+
function getAtomKey(str) {
|
|
255
|
+
return `use${capitalizeFirstLetter(str)}`;
|
|
256
|
+
}
|
|
257
|
+
function createAuthClient(options) {
|
|
258
|
+
const {
|
|
259
|
+
pluginPathMethods,
|
|
260
|
+
pluginsActions,
|
|
261
|
+
pluginsAtoms,
|
|
262
|
+
$fetch,
|
|
263
|
+
atomListeners
|
|
264
|
+
} = getClientConfig(options);
|
|
265
|
+
let resolvedHooks = {};
|
|
266
|
+
for (const [key, value] of Object.entries(pluginsAtoms)) {
|
|
267
|
+
resolvedHooks[getAtomKey(key)] = () => useStore(value);
|
|
268
|
+
}
|
|
269
|
+
const { $session, _sessionSignal } = getSessionAtom($fetch);
|
|
270
|
+
function useSession(initialValue) {
|
|
271
|
+
const [isClient, setIsClient] = useState(false);
|
|
272
|
+
const storeValue = useStore($session);
|
|
273
|
+
useEffect(() => {
|
|
274
|
+
setIsClient(true);
|
|
275
|
+
}, []);
|
|
276
|
+
if (!isClient && initialValue !== void 0) {
|
|
277
|
+
return initialValue;
|
|
241
278
|
}
|
|
279
|
+
return storeValue;
|
|
242
280
|
}
|
|
243
|
-
const
|
|
244
|
-
$atoms: {
|
|
245
|
-
$session
|
|
246
|
-
},
|
|
247
|
-
$fetch,
|
|
281
|
+
const routes = {
|
|
248
282
|
...pluginsActions,
|
|
249
|
-
...
|
|
283
|
+
...resolvedHooks,
|
|
284
|
+
useSession
|
|
250
285
|
};
|
|
251
286
|
const proxy = createDynamicPathProxy(
|
|
252
|
-
|
|
287
|
+
routes,
|
|
253
288
|
$fetch,
|
|
289
|
+
pluginPathMethods,
|
|
254
290
|
{
|
|
255
|
-
...
|
|
256
|
-
|
|
291
|
+
...pluginsAtoms,
|
|
292
|
+
_sessionSignal
|
|
257
293
|
},
|
|
258
|
-
|
|
259
|
-
{
|
|
260
|
-
matcher: (path) => path === "/organization/create",
|
|
261
|
-
atom: "$listOrg"
|
|
262
|
-
},
|
|
263
|
-
{
|
|
264
|
-
matcher: (path) => path.startsWith("/organization"),
|
|
265
|
-
atom: "$activeOrgSignal"
|
|
266
|
-
},
|
|
267
|
-
{
|
|
268
|
-
matcher: (path) => path === "/sign-out" || path.startsWith("/sign-up") || path.startsWith("/sign-in"),
|
|
269
|
-
atom: "$sessionSignal"
|
|
270
|
-
},
|
|
271
|
-
...pluginProxySignals
|
|
272
|
-
],
|
|
273
|
-
{
|
|
274
|
-
$sessionSignal,
|
|
275
|
-
...pluginSignals
|
|
276
|
-
}
|
|
294
|
+
atomListeners
|
|
277
295
|
);
|
|
278
296
|
return proxy;
|
|
279
|
-
}
|
|
297
|
+
}
|
|
280
298
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const $fetch = createAuthFetch(options);
|
|
284
|
-
const hooks = options?.authPlugins?.reduce(
|
|
285
|
-
(acc, plugin) => {
|
|
286
|
-
return {
|
|
287
|
-
...acc,
|
|
288
|
-
...plugin($fetch).integrations?.react?.(useStore) || {}
|
|
289
|
-
};
|
|
290
|
-
},
|
|
291
|
-
{}
|
|
292
|
-
);
|
|
293
|
-
const client = createAuthClient(options, hooks);
|
|
294
|
-
function useSession(initialValue = null) {
|
|
295
|
-
const session = useStore(client.$atoms.$session);
|
|
296
|
-
if (session) {
|
|
297
|
-
return session;
|
|
298
|
-
}
|
|
299
|
-
return initialValue;
|
|
300
|
-
}
|
|
301
|
-
const obj = Object.assign(client, {
|
|
302
|
-
useSession
|
|
303
|
-
});
|
|
304
|
-
return obj;
|
|
305
|
-
};
|
|
306
|
-
var useAuthStore = useStore;
|
|
307
|
-
export {
|
|
308
|
-
createAuthClient2 as createAuthClient,
|
|
309
|
-
useAuthStore
|
|
310
|
-
};
|
|
299
|
+
export { createAuthClient };
|
|
300
|
+
//# sourceMappingURL=react.js.map
|
|
311
301
|
//# sourceMappingURL=react.js.map
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client/react.ts","../src/client/base.ts","../src/error/better-auth-error.ts","../src/utils/base-url.ts","../src/client/fetch-plugins.ts","../src/client/proxy.ts","../src/client/session-atom.ts"],"sourcesContent":["import { useStore } from \"@nanostores/react\";\nimport {\n\tcreateAuthFetch,\n\tcreateAuthClient as createVanillaClient,\n} from \"./base\";\nimport type { AuthPlugin, ClientOptions } from \"./type\";\nimport type { UnionToIntersection } from \"../types/helper\";\n\nexport const createAuthClient = <Option extends ClientOptions>(\n\toptions?: Option,\n) => {\n\tconst $fetch = createAuthFetch(options);\n\tconst hooks = options?.authPlugins?.reduce(\n\t\t(acc, plugin) => {\n\t\t\treturn {\n\t\t\t\t...acc,\n\t\t\t\t...(plugin($fetch).integrations?.react?.(useStore) || {}),\n\t\t\t};\n\t\t},\n\t\t{} as Record<string, any>,\n\t) as Option[\"authPlugins\"] extends Array<infer Pl>\n\t\t? Pl extends AuthPlugin\n\t\t\t? UnionToIntersection<\n\t\t\t\t\tReturnType<Pl>[\"integrations\"] extends\n\t\t\t\t\t\t| {\n\t\t\t\t\t\t\t\treact?: (useStore: any) => infer R;\n\t\t\t\t\t\t }\n\t\t\t\t\t\t| undefined\n\t\t\t\t\t\t? R\n\t\t\t\t\t\t: {}\n\t\t\t\t>\n\t\t\t: {}\n\t\t: {};\n\n\tconst client = createVanillaClient(options, hooks);\n\n\tfunction useSession(\n\t\tinitialValue: typeof client.$atoms.$session.value = null,\n\t) {\n\t\tconst session = useStore(client.$atoms.$session);\n\t\tif (session) {\n\t\t\treturn session;\n\t\t}\n\t\treturn initialValue;\n\t}\n\n\tconst obj = Object.assign(client, {\n\t\tuseSession,\n\t});\n\treturn obj;\n};\n\nexport const useAuthStore = useStore;\n","import { createFetch } from \"@better-fetch/fetch\";\nimport type { Auth } from \"../auth\";\nimport { getBaseURL } from \"../utils/base-url\";\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\nimport type { InferRoutes } from \"./path-to-object\";\nimport { createDynamicPathProxy, type AuthProxySignal } from \"./proxy\";\nimport { getSessionAtom } from \"./session-atom\";\nimport type { AuthPlugin, ClientOptions } from \"./type\";\nimport type { UnionToIntersection } from \"../types/helper\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { BetterAuthPlugin } from \"../types/plugins\";\n\n/**\n * used for plugins only\n */\n\nexport const createAuthFetch = (options?: ClientOptions) => {\n\tconst $baseFetch = createFetch();\n\treturn createFetch({\n\t\tmethod: \"GET\",\n\t\t...options,\n\t\tbaseURL: getBaseURL(options?.baseURL).withPath,\n\t\tplugins: [\n\t\t\t...(options?.plugins || []),\n\t\t\t...(options?.authPlugins\n\t\t\t\t?.flatMap((plugin) => plugin($baseFetch).fetchPlugins)\n\t\t\t\t.filter((plugin) => plugin !== undefined) || []),\n\t\t\t...(options?.csrfPlugin !== false ? [csrfPlugin] : []),\n\t\t\tredirectPlugin,\n\t\t\taddCurrentURL,\n\t\t],\n\t});\n};\n\nexport const createAuthClient = <\n\tO extends ClientOptions = ClientOptions,\n\tAT extends Record<string, any> = {},\n>(\n\toptions?: O,\n\tadditionalActions = {} as AT,\n) => {\n\ttype API = O[\"authPlugins\"] extends Array<any>\n\t\t? (O[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t\t? UnionToIntersection<\n\t\t\t\t\t\t//@ts-expect-error\n\t\t\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\t\t\tplugin: infer Plug;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\t? Plug extends BetterAuthPlugin\n\t\t\t\t\t\t\t\t? Plug[\"endpoints\"]\n\t\t\t\t\t\t\t\t: {}\n\t\t\t\t\t\t\t: {}\n\t\t\t\t\t>\n\t\t\t\t: {}) &\n\t\t\t\tAuth[\"api\"]\n\t\t: Auth[\"api\"];\n\n\tconst $fetch = createAuthFetch(options);\n\n\ttype Plugins = O[\"authPlugins\"] extends Array<AuthPlugin>\n\t\t? Array<ReturnType<O[\"authPlugins\"][number]>[\"plugin\"]>\n\t\t: undefined;\n\t//@ts-expect-error\n\tconst { $session, $sessionSignal } = getSessionAtom<{\n\t\thandler: any;\n\t\tapi: any;\n\t\toptions: {\n\t\t\tdatabase: any;\n\t\t\tplugins: Plugins;\n\t\t};\n\t}>($fetch);\n\n\tlet pluginsActions = {} as Record<string, any>;\n\ttype PluginActions = UnionToIntersection<\n\t\tO[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t? //@ts-expect-error\n\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\tactions?: infer R;\n\t\t\t\t}\n\t\t\t\t? R\n\t\t\t\t: {}\n\t\t\t: {}\n\t>;\n\n\tconst pluginProxySignals: AuthProxySignal[] = [];\n\tlet pluginSignals: Record<string, PreinitializedWritableAtom<boolean>> = {};\n\tlet pluginPathMethods: Record<string, \"POST\" | \"GET\"> = {};\n\n\tfor (const plugin of options?.authPlugins || []) {\n\t\tconst pl = plugin($fetch);\n\t\tif (pl.authProxySignal) {\n\t\t\tpluginProxySignals.push(...pl.authProxySignal);\n\t\t}\n\t\tif (pl.actions) {\n\t\t\tpluginsActions = {\n\t\t\t\t...pluginsActions,\n\t\t\t\t...pl.actions,\n\t\t\t};\n\t\t}\n\t\tif (pl.signals) {\n\t\t\tpluginSignals = {\n\t\t\t\t...pluginSignals,\n\t\t\t\t...pl.signals,\n\t\t\t};\n\t\t}\n\t\tif (pl.pathMethods) {\n\t\t\tpluginPathMethods = {\n\t\t\t\t...pluginPathMethods,\n\t\t\t\t...pl.pathMethods,\n\t\t\t};\n\t\t}\n\t}\n\n\tconst actions = {\n\t\t$atoms: {\n\t\t\t$session,\n\t\t},\n\t\t$fetch,\n\t\t...(pluginsActions as object),\n\t\t...additionalActions,\n\t};\n\n\ttype Actions = typeof actions & PluginActions;\n\n\tconst proxy = createDynamicPathProxy(\n\t\tactions,\n\t\t$fetch,\n\t\t{\n\t\t\t...pluginPathMethods,\n\t\t\t\"/sign-out\": \"POST\",\n\t\t},\n\t\t[\n\t\t\t{\n\t\t\t\tmatcher: (path) => path === \"/organization/create\",\n\t\t\t\tatom: \"$listOrg\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) => path.startsWith(\"/organization\"),\n\t\t\t\tatom: \"$activeOrgSignal\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) =>\n\t\t\t\t\tpath === \"/sign-out\" ||\n\t\t\t\t\tpath.startsWith(\"/sign-up\") ||\n\t\t\t\t\tpath.startsWith(\"/sign-in\"),\n\t\t\t\tatom: \"$sessionSignal\",\n\t\t\t},\n\t\t\t...pluginProxySignals,\n\t\t],\n\t\t{\n\t\t\t$sessionSignal,\n\t\t\t...pluginSignals,\n\t\t},\n\t) as unknown as InferRoutes<API> & Actions;\n\treturn proxy;\n};\n","export class BetterAuthError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t}\n}\n","import { BetterAuthError } from \"../error/better-auth-error\";\n\nfunction checkHasPath(url: string): boolean {\n\ttry {\n\t\tconst parsedUrl = new URL(url);\n\t\treturn parsedUrl.pathname !== \"/\";\n\t} catch (error) {\n\t\tconsole.error(\"Invalid URL:\", error);\n\t\treturn false;\n\t}\n}\n\nfunction withPath(url: string, path = \"/api/auth\") {\n\tconst hasPath = checkHasPath(url);\n\tif (hasPath) {\n\t\treturn {\n\t\t\tbaseURL: new URL(url).origin,\n\t\t\twithPath: url,\n\t\t};\n\t}\n\tpath = path.startsWith(\"/\") ? path : `/${path}`;\n\treturn {\n\t\tbaseURL: url,\n\t\twithPath: `${url}${path}`,\n\t};\n}\n\nexport function getBaseURL(url?: string, path?: string) {\n\tif (url) {\n\t\treturn withPath(url, path);\n\t}\n\tconst env: any = typeof process !== \"undefined\" ? process.env : {};\n\tconst fromEnv =\n\t\tenv.BETTER_AUTH_URL ||\n\t\tenv.AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.PUBLIC_AUTH_URL ||\n\t\tenv.PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_AUTH_URL;\n\tif (fromEnv) {\n\t\treturn withPath(fromEnv, path);\n\t}\n\n\tconst isDev =\n\t\t!fromEnv && (env.NODE_ENV === \"development\" || env.NODE_ENV === \"test\");\n\tif (isDev) {\n\t\treturn {\n\t\t\tbaseURL: \"http://localhost:3000\",\n\t\t\twithPath: \"http://localhost:3000/api/auth\",\n\t\t};\n\t}\n\tthrow new BetterAuthError(\n\t\t\"Could not infer baseURL from environment variables\",\n\t);\n}\n","import { type BetterFetchPlugin, betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport const redirectPlugin = {\n\tid: \"redirect\",\n\tname: \"Redirect\",\n\thooks: {\n\t\tonSuccess(context) {\n\t\t\tif (context.data?.url && context.data?.redirect) {\n\t\t\t\twindow.location.href = context.data.url;\n\t\t\t}\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const addCurrentURL = {\n\tid: \"add-current-url\",\n\tname: \"Add current URL\",\n\thooks: {\n\t\tonRequest(context) {\n\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\tconst url = new URL(context.url);\n\t\t\t\turl.searchParams.set(\"currentURL\", window.location.href);\n\t\t\t\tcontext.url = url;\n\t\t\t}\n\t\t\treturn context;\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const csrfPlugin = {\n\tid: \"csrf\",\n\tname: \"CSRF Check\",\n\tasync init(url, options) {\n\t\tif (options?.method !== \"GET\") {\n\t\t\toptions = options || {};\n\t\t\tconst { data, error } = await betterFetch<{\n\t\t\t\tcsrfToken: string;\n\t\t\t}>(\"/csrf\", {\n\t\t\t\tbody: undefined,\n\t\t\t\tbaseURL: options.baseURL,\n\t\t\t\tplugins: [],\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tcredentials: \"include\",\n\t\t\t});\n\t\t\tif (error?.status === 404) {\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\"Route not found. Make sure the server is running and the base URL is correct and includes the path (e.g. http://localhost:3000/api/auth).\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (error) {\n\t\t\t\tthrow new BetterAuthError(error.message || \"Failed to get CSRF token.\");\n\t\t\t}\n\t\t\toptions.body = {\n\t\t\t\t...options?.body,\n\t\t\t\tcsrfToken: data.csrfToken,\n\t\t\t};\n\t\t}\n\t\toptions.credentials = \"include\";\n\t\treturn { url, options };\n\t},\n} satisfies BetterFetchPlugin;\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { LiteralUnion } from \"../types/helper\";\n\nfunction getMethod(\n\tpath: string,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\targs?: ProxyRequest,\n) {\n\tconst method = knownPathMethods[path];\n\tconst { options, query, ...body } = args || {};\n\tif (method) {\n\t\treturn method;\n\t}\n\tif (options?.method) {\n\t\treturn options.method;\n\t}\n\tif (body && Object.keys(body).length > 0) {\n\t\treturn \"POST\";\n\t}\n\treturn \"GET\";\n}\n\nexport type AuthProxySignal = {\n\tatom: LiteralUnion<string, \"$sessionSignal\">;\n\tmatcher: (path: string) => boolean;\n};\n\nexport function createDynamicPathProxy<T extends Record<string, any>>(\n\troutes: T,\n\tclient: BetterFetch,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\t$signal?: AuthProxySignal[],\n\t$signals?: Record<string, PreinitializedWritableAtom<boolean>>,\n): T {\n\tfunction createProxy(path: string[] = []): any {\n\t\treturn new Proxy(function () {}, {\n\t\t\tget(target, prop: string) {\n\t\t\t\tconst fullPath = [...path, prop];\n\t\t\t\tlet current: any = routes;\n\t\t\t\tfor (const segment of fullPath) {\n\t\t\t\t\tif (current && typeof current === \"object\" && segment in current) {\n\t\t\t\t\t\tcurrent = current[segment];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcurrent = undefined;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (typeof current === \"function\") {\n\t\t\t\t\treturn current;\n\t\t\t\t}\n\n\t\t\t\treturn createProxy(fullPath);\n\t\t\t},\n\t\t\tapply: async (_, __, args) => {\n\t\t\t\tconst routePath =\n\t\t\t\t\t\"/\" +\n\t\t\t\t\tpath\n\t\t\t\t\t\t.map((segment) =>\n\t\t\t\t\t\t\tsegment.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join(\"/\");\n\n\t\t\t\tconst arg = (args[0] || {}) as ProxyRequest;\n\t\t\t\tconst method = getMethod(routePath, knownPathMethods, arg);\n\t\t\t\tconst { query, options, ...body } = arg;\n\n\t\t\t\treturn await client(routePath, {\n\t\t\t\t\t...options,\n\t\t\t\t\tbody: method === \"GET\" ? undefined : body,\n\t\t\t\t\tquery: query,\n\t\t\t\t\tmethod,\n\t\t\t\t\tasync onSuccess(context) {\n\t\t\t\t\t\tconst signal = $signal?.find((s) => s.matcher(routePath));\n\t\t\t\t\t\tif (!signal) return;\n\t\t\t\t\t\tconst signalAtom = $signals?.[signal.atom];\n\t\t\t\t\t\tif (!signalAtom) return;\n\t\t\t\t\t\tsignalAtom.set(!signalAtom.get());\n\t\t\t\t\t\tawait options?.onSuccess?.(context);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\n\treturn createProxy() as T;\n}\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport { atom, computed, task } from \"nanostores\";\nimport type { Auth as BetterAuth } from \"../auth\";\nimport type { Prettify } from \"../types/helper\";\nimport type { InferSession, InferUser } from \"../types/models\";\n\nexport function getSessionAtom<Auth extends BetterAuth>(client: BetterFetch) {\n\ttype UserWithAdditionalFields = InferUser<Auth[\"options\"]>;\n\ttype SessionWithAdditionalFields = InferSession<Auth[\"options\"]>;\n\tconst $signal = atom<boolean>(false);\n\tconst $session = computed($signal, () =>\n\t\ttask(async () => {\n\t\t\tconst session = await client(\"/session\", {\n\t\t\t\tcredentials: \"include\",\n\t\t\t\tmethod: \"GET\",\n\t\t\t});\n\t\t\treturn session.data as {\n\t\t\t\tuser: Prettify<UserWithAdditionalFields>;\n\t\t\t\tsession: Prettify<SessionWithAdditionalFields>;\n\t\t\t} | null;\n\t\t}),\n\t);\n\treturn { $session, $sessionSignal: $signal };\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;;;ACAzB,SAAS,mBAAmB;;;ACArB,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAC1C,YAAY,SAAiB;AAC5B,UAAM,OAAO;AAAA,EACd;AACD;;;ACFA,SAAS,aAAa,KAAs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R,eAAoD,MACnD;AACD,UAAM,UAAU,SAAS,OAAO,OAAO,QAAQ;AAC/C,QAAI,SAAS;AACZ,aAAO;AAAA,IACR;AACA,WAAO;AAAA,EACR;AAEA,QAAM,MAAM,OAAO,OAAO,QAAQ;AAAA,IACjC;AAAA,EACD,CAAC;AACD,SAAO;AACR;AAEO,IAAM,eAAe;","names":["createAuthClient"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/base-url.ts","../src/error/better-auth-error.ts","../src/client/fetch-plugins.ts","../src/client/config.ts","../src/utils/misc.ts","../src/client/proxy.ts","../src/client/session-atom.ts","../src/client/react.ts"],"names":[],"mappings":";;;;;;;;AAAA,SAAS,aAAa,GAAsB,EAAA;AAC3C,EAAI,IAAA;AACH,IAAM,MAAA,SAAA,GAAY,IAAI,GAAA,CAAI,GAAG,CAAA,CAAA;AAC7B,IAAA,OAAO,UAAU,QAAa,KAAA,GAAA,CAAA;AAAA,WACtB,KAAO,EAAA;AACf,IAAQ,OAAA,CAAA,KAAA,CAAM,gBAAgB,KAAK,CAAA,CAAA;AACnC,IAAO,OAAA,KAAA,CAAA;AAAA,GACR;AACD,CAAA;AAEA,SAAS,QAAA,CAAS,GAAa,EAAA,IAAA,GAAO,WAAa,EAAA;AAClD,EAAM,MAAA,OAAA,GAAU,aAAa,GAAG,CAAA,CAAA;AAChC,EAAA,IAAI,OAAS,EAAA;AACZ,IAAO,OAAA,GAAA,CAAA;AAAA,GACR;AACA,EAAA,IAAA,GAAO,KAAK,UAAW,CAAA,GAAG,CAAI,GAAA,IAAA,GAAO,IAAI,IAAI,CAAA,CAAA,CAAA;AAC7C,EAAO,OAAA,CAAA,EAAG,GAAG,CAAA,EAAG,IAAI,CAAA,CAAA,CAAA;AACrB,CAAA;AAEO,SAAS,UAAA,CAAW,KAAc,IAAe,EAAA;AACvD,EAAA,IAAI,GAAK,EAAA;AACR,IAAO,OAAA,QAAA,CAAS,KAAK,IAAI,CAAA,CAAA;AAAA,GAC1B;AACA,EAAA,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2C,EAAA;AAC9D,IAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AAC9C,IAAM,MAAA,UAAA,GAAa,SAAS,QAAQ,CAAA,CAAA;AAEpC,IAAA,SAAA,CAAU,MAAM;AACf,MAAA,WAAA,CAAY,IAAI,CAAA,CAAA;AAAA,KACjB,EAAG,EAAE,CAAA,CAAA;AAEL,IAAI,IAAA,CAAC,QAAY,IAAA,YAAA,KAAiB,KAAW,CAAA,EAAA;AAC5C,MAAO,OAAA,YAAA,CAAA;AAAA,KACR;AACA,IAAO,OAAA,UAAA,CAAA;AAAA,GACR;AACA,EAAA,MAAM,MAAS,GAAA;AAAA,IACd,GAAG,cAAA;AAAA,IACH,GAAG,aAAA;AAAA,IACH,UAAA;AAAA,GACD,CAAA;AACA,EAAA,MAAM,KAAQ,GAAA,sBAAA;AAAA,IACb,MAAA;AAAA,IACA,MAAA;AAAA,IACA,iBAAA;AAAA,IACA;AAAA,MACC,GAAG,YAAA;AAAA,MACH,cAAA;AAAA,KACD;AAAA,IACA,aAAA;AAAA,GACD,CAAA;AACA,EAAO,OAAA,KAAA,CAAA;AAKR","file":"react.js","sourcesContent":["function checkHasPath(url: string): boolean {\n\ttry {\n\t\tconst parsedUrl = new URL(url);\n\t\treturn parsedUrl.pathname !== \"/\";\n\t} catch (error) {\n\t\tconsole.error(\"Invalid URL:\", error);\n\t\treturn false;\n\t}\n}\n\nfunction withPath(url: string, path = \"/api/auth\") {\n\tconst hasPath = checkHasPath(url);\n\tif (hasPath) {\n\t\treturn url;\n\t}\n\tpath = path.startsWith(\"/\") ? path : `/${path}`;\n\treturn `${url}${path}`;\n}\n\nexport function getBaseURL(url?: string, path?: string) {\n\tif (url) {\n\t\treturn withPath(url, path);\n\t}\n\tconst env: any = typeof process !== \"undefined\" ? process.env : {};\n\tconst fromEnv =\n\t\tenv.BETTER_AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_AUTH_URL;\n\tif (fromEnv) {\n\t\treturn withPath(fromEnv, path);\n\t}\n\n\tif (typeof window !== \"undefined\") {\n\t\treturn withPath(window.location.origin, path);\n\t}\n\n\treturn undefined;\n}\n","export class BetterAuthError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t}\n}\n","import { type BetterFetchPlugin, betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport const redirectPlugin = {\n\tid: \"redirect\",\n\tname: \"Redirect\",\n\thooks: {\n\t\tonSuccess(context) {\n\t\t\tif (context.data?.url && context.data?.redirect) {\n\t\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\t\twindow.location.href = context.data.url;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const addCurrentURL = {\n\tid: \"add-current-url\",\n\tname: \"Add current URL\",\n\thooks: {\n\t\tonRequest(context) {\n\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\tconst url = new URL(context.url);\n\t\t\t\turl.searchParams.set(\"currentURL\", window.location.href);\n\t\t\t\tcontext.url = url;\n\t\t\t}\n\t\t\treturn context;\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const csrfPlugin = {\n\tid: \"csrf\",\n\tname: \"CSRF Check\",\n\tasync init(url, options) {\n\t\tif (typeof window !== \"undefined\") {\n\t\t\t/**\n\t\t\t * If origin is the same as baseURL\n\t\t\t * then we don't need to check the CSRF token.\n\t\t\t */\n\t\t\tconst isTheSameOrigin =\n\t\t\t\tnew URL(options?.baseURL || url).origin === window.location.origin;\n\t\t\tif (isTheSameOrigin) {\n\t\t\t\treturn { url, options };\n\t\t\t}\n\t\t}\n\n\t\tif (!options?.baseURL) {\n\t\t\tthrow new BetterAuthError(\n\t\t\t\t\"API Base URL on the auth client isn't configured. Please pass it directly to the client `baseURL`\",\n\t\t\t);\n\t\t}\n\n\t\tif (options?.method !== \"GET\") {\n\t\t\toptions = options || {};\n\t\t\tconst { data, error } = await betterFetch<{\n\t\t\t\tcsrfToken: string;\n\t\t\t}>(\"/csrf\", {\n\t\t\t\tbody: undefined,\n\t\t\t\tbaseURL: options.baseURL,\n\t\t\t\tplugins: [],\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tcredentials: \"include\",\n\t\t\t\tcustomFetchImpl: options.customFetchImpl,\n\t\t\t});\n\t\t\tif (error?.status === 404) {\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\"Route not found. Make sure the server is running and the base URL is correct and includes the path (e.g. http://localhost:3000/api/auth).\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (error) {\n\t\t\t\tthrow new BetterAuthError(error.message || \"Failed to get CSRF token.\");\n\t\t\t}\n\t\t\toptions.body = {\n\t\t\t\t...options?.body,\n\t\t\t\tcsrfToken: data.csrfToken,\n\t\t\t};\n\t\t}\n\t\toptions.credentials = \"include\";\n\t\treturn { url, options };\n\t},\n} satisfies BetterFetchPlugin;\n","import { createFetch } from \"@better-fetch/fetch\";\nimport { getBaseURL } from \"../utils/base-url\";\nimport { type Atom } from \"nanostores\";\nimport type { AtomListener, ClientOptions } from \"./types\";\n\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\n\nexport const getClientConfig = <O extends ClientOptions>(options?: O) => {\n\tconst $fetch = createFetch({\n\t\tbaseURL: getBaseURL(options?.fetchOptions?.baseURL || options?.baseURL),\n\t\t...options?.fetchOptions,\n\t\tplugins: [\n\t\t\tcsrfPlugin,\n\t\t\tredirectPlugin,\n\t\t\taddCurrentURL,\n\t\t\t...(options?.fetchOptions?.plugins || []),\n\t\t\t...(options?.plugins\n\t\t\t\t?.flatMap((plugin) => plugin.fetchPlugins)\n\t\t\t\t.filter((pl) => pl !== undefined) || []),\n\t\t],\n\t});\n\tconst plugins = options?.plugins || [];\n\tlet pluginsActions = {} as Record<string, any>;\n\tlet pluginsAtoms = {} as Record<string, Atom<any>>;\n\tlet pluginPathMethods: Record<string, \"POST\" | \"GET\"> = {\n\t\t\"/sign-out\": \"POST\",\n\t};\n\tconst atomListeners: AtomListener[] = [\n\t\t{\n\t\t\tsignal: \"_sessionSignal\",\n\t\t\tmatcher(path) {\n\t\t\t\treturn path === \"/sign-out\" || path === \"sign-up/email\";\n\t\t\t},\n\t\t},\n\t];\n\tfor (const plugin of plugins) {\n\t\tif (plugin.getActions) {\n\t\t\tObject.assign(pluginsActions, plugin.getActions?.($fetch));\n\t\t}\n\t\tif (plugin.getAtoms) {\n\t\t\tObject.assign(pluginsAtoms, plugin.getAtoms?.($fetch));\n\t\t}\n\t\tif (plugin.pathMethods) {\n\t\t\tObject.assign(pluginPathMethods, plugin.pathMethods);\n\t\t}\n\t\tif (plugin.atomListeners) {\n\t\t\tatomListeners.push(...plugin.atomListeners);\n\t\t}\n\t}\n\treturn {\n\t\tpluginsActions,\n\t\tpluginsAtoms,\n\t\tpluginPathMethods,\n\t\tatomListeners,\n\t\t$fetch,\n\t};\n};\n","export function capitalizeFirstLetter(str: string) {\n\treturn str.charAt(0).toUpperCase() + str.slice(1);\n}\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport type { Atom, PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { AuthClientPlugin } from \"./types\";\n\nfunction getMethod(\n\tpath: string,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\targs?: ProxyRequest,\n) {\n\tconst method = knownPathMethods[path];\n\tconst { options, query, ...body } = args || {};\n\tif (method) {\n\t\treturn method;\n\t}\n\tif (options?.method) {\n\t\treturn options.method;\n\t}\n\tif (body && Object.keys(body).length > 0) {\n\t\treturn \"POST\";\n\t}\n\treturn \"GET\";\n}\n\nexport type AuthProxySignal = {\n\tatom: PreinitializedWritableAtom<boolean>;\n\tmatcher: (path: string) => boolean;\n};\n\nexport function createDynamicPathProxy<T extends Record<string, any>>(\n\troutes: T,\n\tclient: BetterFetch,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\tatoms: Record<string, Atom>,\n\tatomListeners: AuthClientPlugin[\"atomListeners\"],\n): T {\n\tfunction createProxy(path: string[] = []): any {\n\t\treturn new Proxy(function () {}, {\n\t\t\tget(target, prop: string) {\n\t\t\t\tconst fullPath = [...path, prop];\n\t\t\t\tlet current: any = routes;\n\t\t\t\tfor (const segment of fullPath) {\n\t\t\t\t\tif (current && typeof current === \"object\" && segment in current) {\n\t\t\t\t\t\tcurrent = current[segment];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcurrent = undefined;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (typeof current === \"function\") {\n\t\t\t\t\treturn current;\n\t\t\t\t}\n\t\t\t\treturn createProxy(fullPath);\n\t\t\t},\n\t\t\tapply: async (_, __, args) => {\n\t\t\t\tconst routePath =\n\t\t\t\t\t\"/\" +\n\t\t\t\t\tpath\n\t\t\t\t\t\t.map((segment) =>\n\t\t\t\t\t\t\tsegment.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join(\"/\");\n\n\t\t\t\tconst arg = (args[0] || {}) as ProxyRequest;\n\t\t\t\tconst method = getMethod(routePath, knownPathMethods, arg);\n\t\t\t\tconst { query, options, ...body } = arg;\n\n\t\t\t\treturn await client(routePath, {\n\t\t\t\t\t...options,\n\t\t\t\t\tbody:\n\t\t\t\t\t\tmethod === \"GET\"\n\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\t...body,\n\t\t\t\t\t\t\t\t\t...(options?.body || {}),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\tquery: query,\n\t\t\t\t\tmethod,\n\t\t\t\t\tasync onSuccess(context) {\n\t\t\t\t\t\tawait options?.onSuccess?.(context);\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * We trigger listeners\n\t\t\t\t\t\t */\n\t\t\t\t\t\tconst matches = atomListeners?.find((s) => s.matcher(routePath));\n\t\t\t\t\t\tif (!matches) return;\n\t\t\t\t\t\tconst signal = atoms[matches.signal];\n\t\t\t\t\t\tif (!signal) return;\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * To avoid race conditions we set the signal in a setTimeout\n\t\t\t\t\t\t */\n\t\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\t\t//@ts-expect-error\n\t\t\t\t\t\t\tsignal.set(!signal.get());\n\t\t\t\t\t\t}, 0);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\n\treturn createProxy() as T;\n}\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport { atom, computed, task } from \"nanostores\";\nimport type { Auth as BetterAuth } from \"../auth\";\nimport type { Prettify } from \"../types/helper\";\nimport type { InferSession, InferUser } from \"../types/models\";\nimport type { AuthClientPlugin, ClientOptions } from \"./types\";\n\nexport function getSessionAtom<Option extends ClientOptions>(\n\tclient: BetterFetch,\n) {\n\ttype Plugins = Option[\"plugins\"] extends Array<AuthClientPlugin>\n\t\t? Array<Option[\"plugins\"][number][\"$InferServerPlugin\"]>\n\t\t: undefined;\n\n\ttype Auth = {\n\t\thandler: any;\n\t\tapi: any;\n\t\toptions: {\n\t\t\tdatabase: any;\n\t\t\tplugins: Plugins;\n\t\t};\n\t};\n\n\ttype UserWithAdditionalFields = InferUser<\n\t\tAuth extends BetterAuth ? Auth : never\n\t>;\n\n\t//@ts-expect-error\n\ttype SessionWithAdditionalFields = InferSession<Auth[\"options\"]>;\n\tconst $signal = atom<boolean>(false);\n\tconst $session = computed($signal, () =>\n\t\ttask(async () => {\n\t\t\tconst session = await client(\"/session\", {\n\t\t\t\tcredentials: \"include\",\n\t\t\t\tmethod: \"GET\",\n\t\t\t});\n\t\t\treturn session.data as {\n\t\t\t\tuser: Prettify<UserWithAdditionalFields>;\n\t\t\t\tsession: Prettify<SessionWithAdditionalFields>;\n\t\t\t} | null;\n\t\t}),\n\t);\n\treturn { $session, _sessionSignal: $signal };\n}\n","import { useStore } from \"@nanostores/react\";\nimport { getClientConfig } from \"./config\";\nimport { capitalizeFirstLetter } from \"../utils/misc\";\nimport type {\n\tAuthClientPlugin,\n\tClientOptions,\n\tInferActions,\n\tInferClientAPI,\n\tIsSignal,\n} from \"./types\";\nimport { createDynamicPathProxy } from \"./proxy\";\nimport { getSessionAtom } from \"./session-atom\";\nimport type { UnionToIntersection } from \"../types/helper\";\nimport { useEffect, useState } from \"react\";\n\nfunction getAtomKey(str: string) {\n\treturn `use${capitalizeFirstLetter(str)}`;\n}\n\ntype InferResolvedHooks<O extends ClientOptions> = O[\"plugins\"] extends Array<\n\tinfer Plugin\n>\n\t? Plugin extends AuthClientPlugin\n\t\t? Plugin[\"getAtoms\"] extends (fetch: any) => infer Atoms\n\t\t\t? Atoms extends Record<string, any>\n\t\t\t\t? {\n\t\t\t\t\t\t[key in keyof Atoms as IsSignal<key> extends true\n\t\t\t\t\t\t\t? never\n\t\t\t\t\t\t\t: key extends string\n\t\t\t\t\t\t\t\t? `use${Capitalize<key>}`\n\t\t\t\t\t\t\t\t: never]: () => ReturnType<Atoms[key][\"get\"]>;\n\t\t\t\t\t}\n\t\t\t\t: {}\n\t\t\t: {}\n\t\t: {}\n\t: {};\n\nexport function createAuthClient<Option extends ClientOptions>(\n\toptions?: Option,\n) {\n\tconst {\n\t\tpluginPathMethods,\n\t\tpluginsActions,\n\t\tpluginsAtoms,\n\t\t$fetch,\n\t\tatomListeners,\n\t} = getClientConfig(options);\n\tlet resolvedHooks: Record<string, any> = {};\n\tfor (const [key, value] of Object.entries(pluginsAtoms)) {\n\t\tresolvedHooks[getAtomKey(key)] = () => useStore(value);\n\t}\n\tconst { $session, _sessionSignal } = getSessionAtom<Option>($fetch);\n\n\tfunction useSession(initialValue?: (typeof $session)[\"value\"]) {\n\t\tconst [isClient, setIsClient] = useState(false);\n\t\tconst storeValue = useStore($session);\n\n\t\tuseEffect(() => {\n\t\t\tsetIsClient(true);\n\t\t}, []);\n\n\t\tif (!isClient && initialValue !== undefined) {\n\t\t\treturn initialValue;\n\t\t}\n\t\treturn storeValue;\n\t}\n\tconst routes = {\n\t\t...pluginsActions,\n\t\t...resolvedHooks,\n\t\tuseSession,\n\t};\n\tconst proxy = createDynamicPathProxy(\n\t\troutes,\n\t\t$fetch,\n\t\tpluginPathMethods,\n\t\t{\n\t\t\t...pluginsAtoms,\n\t\t\t_sessionSignal,\n\t\t},\n\t\tatomListeners,\n\t);\n\treturn proxy as UnionToIntersection<InferResolvedHooks<Option>> &\n\t\tInferClientAPI<Option> &\n\t\tInferActions<Option> & {\n\t\t\tuseSession: typeof useSession;\n\t\t};\n}\n"]}
|
package/dist/social.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { h as AppleOptions, f as AppleProfile, j as DiscordOptions, D as DiscordProfile, p as FacebookOptions, F as FacebookProfile, b as GithubOptions, G as GithubProfile, d as GoogleOptions, c as GoogleProfile, O as OAuthProvider, w as OAuthProviderList, m as SpotifyOptions, l as SpotifyProfile, n as TwitchOptions, T as TwitchProfile, u as TwitterOption, r as TwitterProfile, i as apple, k as discord, q as facebook, g as github, e as google, a as oAuthProviderList, o as oAuthProviders, s as spotify, t as twitch, v as twitter } from './
|
|
1
|
+
export { h as AppleOptions, f as AppleProfile, j as DiscordOptions, D as DiscordProfile, p as FacebookOptions, F as FacebookProfile, b as GithubOptions, G as GithubProfile, d as GoogleOptions, c as GoogleProfile, O as OAuthProvider, w as OAuthProviderList, P as ProviderOptions, m as SpotifyOptions, l as SpotifyProfile, n as TwitchOptions, T as TwitchProfile, u as TwitterOption, r as TwitterProfile, i as apple, k as discord, q as facebook, g as github, e as google, a as oAuthProviderList, o as oAuthProviders, s as spotify, t as twitch, v as twitter } from './index-CcxejJTH.js';
|
|
2
2
|
import 'arctic';
|
|
3
3
|
import 'zod';
|
|
4
|
-
import './helper-
|
|
4
|
+
import './helper-D8dhRz72.js';
|