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.
Files changed (58) hide show
  1. package/dist/access.d.ts +3 -4
  2. package/dist/access.js +3 -13
  3. package/dist/access.js.map +1 -1
  4. package/dist/cli.d.ts +1 -2
  5. package/dist/cli.js +36 -44
  6. package/dist/cli.js.map +1 -1
  7. package/dist/client/plugins.d.ts +97 -2407
  8. package/dist/client/plugins.js +143 -203
  9. package/dist/client/plugins.js.map +1 -1
  10. package/dist/client.d.ts +159 -1213
  11. package/dist/client.js +125 -527
  12. package/dist/client.js.map +1 -1
  13. package/dist/{helper-B5_2Vzba.d.ts → helper-D8dhRz72.d.ts} +1 -4
  14. package/dist/{index-Dg4eEXZW.d.ts → index-B9jOjqnF.d.ts} +1 -1
  15. package/dist/{schema-BOszzrbQ.d.ts → index-CcxejJTH.d.ts} +172 -142
  16. package/dist/{client-CaF9eUcv.d.ts → index-Dwhjsk4l.d.ts} +2014 -1971
  17. package/dist/index.d.ts +1124 -6
  18. package/dist/index.js +737 -707
  19. package/dist/index.js.map +1 -1
  20. package/dist/internal-adapter-CVKQ4XR9.d.ts +637 -0
  21. package/dist/next-js.d.ts +17 -7
  22. package/dist/next-js.js +20 -3
  23. package/dist/next-js.js.map +1 -1
  24. package/dist/plugins.d.ts +12 -883
  25. package/dist/plugins.js +743 -679
  26. package/dist/plugins.js.map +1 -1
  27. package/dist/react.d.ts +312 -12
  28. package/dist/react.js +138 -148
  29. package/dist/react.js.map +1 -1
  30. package/dist/social.d.ts +2 -2
  31. package/dist/social.js +179 -151
  32. package/dist/social.js.map +1 -1
  33. package/dist/solid-start.d.ts +7 -6
  34. package/dist/solid-start.js +3 -3
  35. package/dist/solid-start.js.map +1 -1
  36. package/dist/solid.d.ts +91 -2713
  37. package/dist/solid.js +130 -139
  38. package/dist/solid.js.map +1 -1
  39. package/dist/{statement-COylZd3J.d.ts → statement-D6SPoYOh.d.ts} +7 -7
  40. package/dist/svelte-kit.d.ts +6 -5
  41. package/dist/svelte-kit.js +10 -9
  42. package/dist/svelte-kit.js.map +1 -1
  43. package/dist/svelte.d.ts +89 -2713
  44. package/dist/svelte.js +124 -138
  45. package/dist/svelte.js.map +1 -1
  46. package/dist/types-D4WrjKeJ.d.ts +81 -0
  47. package/dist/types.d.ts +31 -5
  48. package/dist/types.js +2 -0
  49. package/dist/types.js.map +1 -1
  50. package/dist/vue.d.ts +313 -12
  51. package/dist/vue.js +131 -145
  52. package/dist/vue.js.map +1 -1
  53. package/package.json +8 -3
  54. package/dist/index-CGeV0d2g.d.ts +0 -1498
  55. package/dist/preact.d.ts +0 -8
  56. package/dist/preact.js +0 -291
  57. package/dist/preact.js.map +0 -1
  58. package/dist/type-tYx_kmry.d.ts +0 -5724
package/dist/solid.js CHANGED
@@ -1,12 +1,8 @@
1
- // src/client/base.ts
2
- import { createFetch } from "@better-fetch/fetch";
1
+ import { useStore } from '@nanostores/solid';
2
+ import { createFetch, betterFetch } from '@better-fetch/fetch';
3
+ import { atom, computed, task } from 'nanostores';
3
4
 
4
- // src/error/better-auth-error.ts
5
- var BetterAuthError = class extends Error {
6
- constructor(message) {
7
- super(message);
8
- }
9
- };
5
+ // src/client/solid.ts
10
6
 
11
7
  // src/utils/base-url.ts
12
8
  function checkHasPath(url) {
@@ -21,47 +17,43 @@ function checkHasPath(url) {
21
17
  function withPath(url, path = "/api/auth") {
22
18
  const hasPath = checkHasPath(url);
23
19
  if (hasPath) {
24
- return {
25
- baseURL: new URL(url).origin,
26
- withPath: url
27
- };
20
+ return url;
28
21
  }
29
22
  path = path.startsWith("/") ? path : `/${path}`;
30
- return {
31
- baseURL: url,
32
- withPath: `${url}${path}`
33
- };
23
+ return `${url}${path}`;
34
24
  }
35
25
  function getBaseURL(url, path) {
36
26
  if (url) {
37
27
  return withPath(url, path);
38
28
  }
39
29
  const env = typeof process !== "undefined" ? process.env : {};
40
- const fromEnv = env.BETTER_AUTH_URL || env.AUTH_URL || env.NEXT_PUBLIC_AUTH_URL || env.NEXT_PUBLIC_BETTER_AUTH_URL || env.PUBLIC_AUTH_URL || env.PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_AUTH_URL;
30
+ 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;
41
31
  if (fromEnv) {
42
32
  return withPath(fromEnv, path);
43
33
  }
44
- const isDev = !fromEnv && (env.NODE_ENV === "development" || env.NODE_ENV === "test");
45
- if (isDev) {
46
- return {
47
- baseURL: "http://localhost:3000",
48
- withPath: "http://localhost:3000/api/auth"
49
- };
34
+ if (typeof window !== "undefined") {
35
+ return withPath(window.location.origin, path);
50
36
  }
51
- throw new BetterAuthError(
52
- "Could not infer baseURL from environment variables"
53
- );
37
+ return void 0;
54
38
  }
55
39
 
40
+ // src/error/better-auth-error.ts
41
+ var BetterAuthError = class extends Error {
42
+ constructor(message) {
43
+ super(message);
44
+ }
45
+ };
46
+
56
47
  // src/client/fetch-plugins.ts
57
- import { betterFetch } from "@better-fetch/fetch";
58
48
  var redirectPlugin = {
59
49
  id: "redirect",
60
50
  name: "Redirect",
61
51
  hooks: {
62
52
  onSuccess(context) {
63
53
  if (context.data?.url && context.data?.redirect) {
64
- window.location.href = context.data.url;
54
+ if (typeof window !== "undefined") {
55
+ window.location.href = context.data.url;
56
+ }
65
57
  }
66
58
  }
67
59
  }
@@ -84,6 +76,17 @@ var csrfPlugin = {
84
76
  id: "csrf",
85
77
  name: "CSRF Check",
86
78
  async init(url, options) {
79
+ if (typeof window !== "undefined") {
80
+ const isTheSameOrigin = new URL(options?.baseURL || url).origin === window.location.origin;
81
+ if (isTheSameOrigin) {
82
+ return { url, options };
83
+ }
84
+ }
85
+ if (!options?.baseURL) {
86
+ throw new BetterAuthError(
87
+ "API Base URL on the auth client isn't configured. Please pass it directly to the client `baseURL`"
88
+ );
89
+ }
87
90
  if (options?.method !== "GET") {
88
91
  options = options || {};
89
92
  const { data, error } = await betterFetch("/csrf", {
@@ -91,7 +94,8 @@ var csrfPlugin = {
91
94
  baseURL: options.baseURL,
92
95
  plugins: [],
93
96
  method: "GET",
94
- credentials: "include"
97
+ credentials: "include",
98
+ customFetchImpl: options.customFetchImpl
95
99
  });
96
100
  if (error?.status === 404) {
97
101
  throw new BetterAuthError(
@@ -111,6 +115,56 @@ var csrfPlugin = {
111
115
  }
112
116
  };
113
117
 
118
+ // src/client/config.ts
119
+ var getClientConfig = (options) => {
120
+ const $fetch = createFetch({
121
+ baseURL: getBaseURL(options?.fetchOptions?.baseURL || options?.baseURL),
122
+ ...options?.fetchOptions,
123
+ plugins: [
124
+ csrfPlugin,
125
+ redirectPlugin,
126
+ addCurrentURL,
127
+ ...options?.fetchOptions?.plugins || [],
128
+ ...options?.plugins?.flatMap((plugin) => plugin.fetchPlugins).filter((pl) => pl !== void 0) || []
129
+ ]
130
+ });
131
+ const plugins = options?.plugins || [];
132
+ let pluginsActions = {};
133
+ let pluginsAtoms = {};
134
+ let pluginPathMethods = {
135
+ "/sign-out": "POST"
136
+ };
137
+ const atomListeners = [
138
+ {
139
+ signal: "_sessionSignal",
140
+ matcher(path) {
141
+ return path === "/sign-out" || path === "sign-up/email";
142
+ }
143
+ }
144
+ ];
145
+ for (const plugin of plugins) {
146
+ if (plugin.getActions) {
147
+ Object.assign(pluginsActions, plugin.getActions?.($fetch));
148
+ }
149
+ if (plugin.getAtoms) {
150
+ Object.assign(pluginsAtoms, plugin.getAtoms?.($fetch));
151
+ }
152
+ if (plugin.pathMethods) {
153
+ Object.assign(pluginPathMethods, plugin.pathMethods);
154
+ }
155
+ if (plugin.atomListeners) {
156
+ atomListeners.push(...plugin.atomListeners);
157
+ }
158
+ }
159
+ return {
160
+ pluginsActions,
161
+ pluginsAtoms,
162
+ pluginPathMethods,
163
+ atomListeners,
164
+ $fetch
165
+ };
166
+ };
167
+
114
168
  // src/client/proxy.ts
115
169
  function getMethod(path, knownPathMethods, args) {
116
170
  const method = knownPathMethods[path];
@@ -126,7 +180,7 @@ function getMethod(path, knownPathMethods, args) {
126
180
  }
127
181
  return "GET";
128
182
  }
129
- function createDynamicPathProxy(routes, client, knownPathMethods, $signal, $signals) {
183
+ function createDynamicPathProxy(routes, client, knownPathMethods, atoms, atomListeners) {
130
184
  function createProxy(path = []) {
131
185
  return new Proxy(function() {
132
186
  }, {
@@ -155,16 +209,21 @@ function createDynamicPathProxy(routes, client, knownPathMethods, $signal, $sign
155
209
  const { query, options, ...body } = arg;
156
210
  return await client(routePath, {
157
211
  ...options,
158
- body: method === "GET" ? void 0 : body,
212
+ body: method === "GET" ? void 0 : {
213
+ ...body,
214
+ ...options?.body || {}
215
+ },
159
216
  query,
160
217
  method,
161
218
  async onSuccess(context) {
162
- const signal = $signal?.find((s) => s.matcher(routePath));
163
- if (!signal) return;
164
- const signalAtom = $signals?.[signal.atom];
165
- if (!signalAtom) return;
166
- signalAtom.set(!signalAtom.get());
167
219
  await options?.onSuccess?.(context);
220
+ const matches = atomListeners?.find((s) => s.matcher(routePath));
221
+ if (!matches) return;
222
+ const signal = atoms[matches.signal];
223
+ if (!signal) return;
224
+ setTimeout(() => {
225
+ signal.set(!signal.get());
226
+ }, 0);
168
227
  }
169
228
  });
170
229
  }
@@ -173,8 +232,10 @@ function createDynamicPathProxy(routes, client, knownPathMethods, $signal, $sign
173
232
  return createProxy();
174
233
  }
175
234
 
176
- // src/client/session-atom.ts
177
- import { atom, computed, task } from "nanostores";
235
+ // src/utils/misc.ts
236
+ function capitalizeFirstLetter(str) {
237
+ return str.charAt(0).toUpperCase() + str.slice(1);
238
+ }
178
239
  function getSessionAtom(client) {
179
240
  const $signal = atom(false);
180
241
  const $session = computed(
@@ -187,117 +248,47 @@ function getSessionAtom(client) {
187
248
  return session.data;
188
249
  })
189
250
  );
190
- return { $session, $sessionSignal: $signal };
251
+ return { $session, _sessionSignal: $signal };
191
252
  }
192
253
 
193
- // src/client/base.ts
194
- var createAuthFetch = (options) => {
195
- const $baseFetch = createFetch();
196
- return createFetch({
197
- method: "GET",
198
- ...options,
199
- baseURL: getBaseURL(options?.baseURL).withPath,
200
- plugins: [
201
- ...options?.plugins || [],
202
- ...options?.authPlugins?.flatMap((plugin) => plugin($baseFetch).fetchPlugins).filter((plugin) => plugin !== void 0) || [],
203
- ...options?.csrfPlugin !== false ? [csrfPlugin] : [],
204
- redirectPlugin,
205
- addCurrentURL
206
- ]
207
- });
208
- };
209
- var createAuthClient = (options, additionalActions = {}) => {
210
- const $fetch = createAuthFetch(options);
211
- const { $session, $sessionSignal } = getSessionAtom($fetch);
212
- let pluginsActions = {};
213
- const pluginProxySignals = [];
214
- let pluginSignals = {};
215
- let pluginPathMethods = {};
216
- for (const plugin of options?.authPlugins || []) {
217
- const pl = plugin($fetch);
218
- if (pl.authProxySignal) {
219
- pluginProxySignals.push(...pl.authProxySignal);
220
- }
221
- if (pl.actions) {
222
- pluginsActions = {
223
- ...pluginsActions,
224
- ...pl.actions
225
- };
226
- }
227
- if (pl.signals) {
228
- pluginSignals = {
229
- ...pluginSignals,
230
- ...pl.signals
231
- };
232
- }
233
- if (pl.pathMethods) {
234
- pluginPathMethods = {
235
- ...pluginPathMethods,
236
- ...pl.pathMethods
237
- };
238
- }
239
- }
240
- const actions = {
241
- $atoms: {
242
- $session
243
- },
254
+ // src/client/solid.ts
255
+ function getAtomKey(str) {
256
+ return `use${capitalizeFirstLetter(str)}`;
257
+ }
258
+ function createAuthClient(options) {
259
+ const {
260
+ pluginPathMethods,
261
+ pluginsActions,
262
+ pluginsAtoms,
244
263
  $fetch,
264
+ atomListeners
265
+ } = getClientConfig(options);
266
+ let resolvedHooks = {};
267
+ for (const [key, value] of Object.entries(pluginsAtoms)) {
268
+ resolvedHooks[getAtomKey(key)] = () => useStore(value);
269
+ }
270
+ const { $session, _sessionSignal } = getSessionAtom($fetch);
271
+ function useSession() {
272
+ return useStore($session);
273
+ }
274
+ const routes = {
245
275
  ...pluginsActions,
246
- ...additionalActions
276
+ ...resolvedHooks,
277
+ useSession
247
278
  };
248
279
  const proxy = createDynamicPathProxy(
249
- actions,
280
+ routes,
250
281
  $fetch,
282
+ pluginPathMethods,
251
283
  {
252
- ...pluginPathMethods,
253
- "/sign-out": "POST"
284
+ ...pluginsAtoms,
285
+ _sessionSignal
254
286
  },
255
- [
256
- {
257
- matcher: (path) => path === "/organization/create",
258
- atom: "$listOrg"
259
- },
260
- {
261
- matcher: (path) => path.startsWith("/organization"),
262
- atom: "$activeOrgSignal"
263
- },
264
- {
265
- matcher: (path) => path === "/sign-out" || path.startsWith("/sign-up") || path.startsWith("/sign-in"),
266
- atom: "$sessionSignal"
267
- },
268
- ...pluginProxySignals
269
- ],
270
- {
271
- $sessionSignal,
272
- ...pluginSignals
273
- }
287
+ atomListeners
274
288
  );
275
289
  return proxy;
276
- };
290
+ }
277
291
 
278
- // src/client/solid.ts
279
- import { useStore } from "@nanostores/solid";
280
- var createAuthClient2 = (options) => {
281
- const $fetch = createAuthFetch(options);
282
- const hooks = options?.authPlugins?.reduce(
283
- (acc, plugin) => {
284
- return {
285
- ...acc,
286
- ...plugin($fetch).integrations?.solid?.(useStore) || {}
287
- };
288
- },
289
- {}
290
- );
291
- const client = createAuthClient(options, hooks);
292
- function useSession() {
293
- return useStore(client.$atoms.$session);
294
- }
295
- const obj = Object.assign(client, {
296
- useSession
297
- });
298
- return obj;
299
- };
300
- export {
301
- createAuthClient2 as createAuthClient
302
- };
292
+ export { createAuthClient };
293
+ //# sourceMappingURL=solid.js.map
303
294
  //# sourceMappingURL=solid.js.map
package/dist/solid.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../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","../src/client/solid.ts"],"sourcesContent":["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","import type { AuthPlugin, ClientOptions } from \"./type\";\nimport { createAuthFetch, createAuthClient as createClient } from \"./base\";\nimport { useStore } from \"@nanostores/solid\";\nimport type * as SolidJS from \"solid-js\"; //to fix ts error: This is likely not portable. A type annotation is necessary.\nimport type { UnionToIntersection } from \"../types/helper\";\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?.solid?.(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 = createClient(options, hooks);\n\n\tfunction useSession() {\n\t\treturn useStore(client.$atoms.$session);\n\t}\n\tconst obj = Object.assign(client, {\n\t\tuseSession,\n\t});\n\treturn obj;\n};\n"],"mappings":";AAAA,SAAS,mBAAmB;;;ACArB,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAC1C,YAAY,SAAiB;AAC5B,UAAM,OAAO;AAAA,EACd;AACD;;;ACFA,SAAS,aAAa,KAAsB;AAC3C,MAAI;AACH,UAAM,YAAY,IAAI,IAAI,GAAG;AAC7B,WAAO,UAAU,aAAa;AAAA,EAC/B,SAAS,OAAO;AACf,YAAQ,MAAM,gBAAgB,KAAK;AACnC,WAAO;AAAA,EACR;AACD;AAEA,SAAS,SAAS,KAAa,OAAO,aAAa;AAClD,QAAM,UAAU,aAAa,GAAG;AAChC,MAAI,SAAS;AACZ,WAAO;AAAA,MACN,SAAS,IAAI,IAAI,GAAG,EAAE;AAAA,MACtB,UAAU;AAAA,IACX;AAAA,EACD;AACA,SAAO,KAAK,WAAW,GAAG,IAAI,OAAO,IAAI,IAAI;AAC7C,SAAO;AAAA,IACN,SAAS;AAAA,IACT,UAAU,GAAG,GAAG,GAAG,IAAI;AAAA,EACxB;AACD;AAEO,SAAS,WAAW,KAAc,MAAe;AACvD,MAAI,KAAK;AACR,WAAO,SAAS,KAAK,IAAI;AAAA,EAC1B;AACA,QAAM,MAAW,OAAO,YAAY,cAAc,QAAQ,MAAM,CAAC;AACjE,QAAM,UACL,IAAI,mBACJ,IAAI,YACJ,IAAI,wBACJ,IAAI,+BACJ,IAAI,mBACJ,IAAI,0BACJ,IAAI,+BACJ,IAAI;AACL,MAAI,SAAS;AACZ,WAAO,SAAS,SAAS,IAAI;AAAA,EAC9B;AAEA,QAAM,QACL,CAAC,YAAY,IAAI,aAAa,iBAAiB,IAAI,aAAa;AACjE,MAAI,OAAO;AACV,WAAO;AAAA,MACN,SAAS;AAAA,MACT,UAAU;AAAA,IACX;AAAA,EACD;AACA,QAAM,IAAI;AAAA,IAC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M,SAAS,gBAAgB,OAAO;AACtC,QAAM,QAAQ,SAAS,aAAa;AAAA,IACnC,CAAC,KAAK,WAAW;AAChB,aAAO;AAAA,QACN,GAAG;AAAA,QACH,GAAI,OAAO,MAAM,EAAE,cAAc,QAAQ,QAAQ,KAAK,CAAC;AAAA,MACxD;AAAA,IACD;AAAA,IACA,CAAC;AAAA,EACF;AAcA,QAAM,SAAS,iBAAa,SAAS,KAAK;AAE1C,WAAS,aAAa;AACrB,WAAO,SAAS,OAAO,OAAO,QAAQ;AAAA,EACvC;AACA,QAAM,MAAM,OAAO,OAAO,QAAQ;AAAA,IACjC;AAAA,EACD,CAAC;AACD,SAAO;AACR;","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/client/proxy.ts","../src/utils/misc.ts","../src/client/session-atom.ts","../src/client/solid.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,EA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,aAAA,CAAc,WAAW,GAAG,CAAC,CAAI,GAAA,MAAM,SAAS,KAAK,CAAA,CAAA;AAAA,GACtD;AACA,EAAA,MAAM,EAAE,QAAA,EAAU,cAAe,EAAA,GAAI,eAAuB,MAAM,CAAA,CAAA;AAElE,EAAA,SAAS,UAAa,GAAA;AACrB,IAAA,OAAO,SAAS,QAAQ,CAAA,CAAA;AAAA,GACzB;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":"solid.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","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","export function capitalizeFirstLetter(str: string) {\n\treturn str.charAt(0).toUpperCase() + str.slice(1);\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/solid\";\nimport { getClientConfig } from \"./config\";\nimport { createDynamicPathProxy } from \"./proxy\";\nimport { capitalizeFirstLetter } from \"../utils/misc\";\nimport type {\n\tAuthClientPlugin,\n\tClientOptions,\n\tInferActions,\n\tInferClientAPI,\n\tIsSignal,\n} from \"./types\";\nimport type { Accessor } from \"solid-js\";\nimport { getSessionAtom } from \"./session-atom\";\nimport type { UnionToIntersection } from \"../types/helper\";\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]: () => Accessor<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() {\n\t\treturn useStore($session);\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"]}
@@ -1,4 +1,4 @@
1
- import { L as LiteralString } from './helper-B5_2Vzba.js';
1
+ import { L as LiteralString } from './helper-D8dhRz72.js';
2
2
 
3
3
  type SubArray<T extends unknown[] | readonly unknown[] | any[]> = T[number][];
4
4
  type Subset<K extends keyof R, R extends Record<string | LiteralString, readonly string[] | readonly LiteralString[]>> = {
@@ -45,33 +45,33 @@ declare const defaultAc: AccessControl<{
45
45
  readonly member: readonly ["create", "update", "delete"];
46
46
  readonly invitation: readonly ["create", "cancel"];
47
47
  }>;
48
- declare const adminAc: Role<Subset<"member" | "organization" | "invitation", {
48
+ declare const adminAc: Role<Subset<"organization" | "member" | "invitation", {
49
49
  readonly organization: readonly ["update", "delete"];
50
50
  readonly member: readonly ["create", "update", "delete"];
51
51
  readonly invitation: readonly ["create", "cancel"];
52
52
  }>>;
53
- declare const ownerAc: Role<Subset<"member" | "organization" | "invitation", {
53
+ declare const ownerAc: Role<Subset<"organization" | "member" | "invitation", {
54
54
  readonly organization: readonly ["update", "delete"];
55
55
  readonly member: readonly ["create", "update", "delete"];
56
56
  readonly invitation: readonly ["create", "cancel"];
57
57
  }>>;
58
- declare const memberAc: Role<Subset<"member" | "organization" | "invitation", {
58
+ declare const memberAc: Role<Subset<"organization" | "member" | "invitation", {
59
59
  readonly organization: readonly ["update", "delete"];
60
60
  readonly member: readonly ["create", "update", "delete"];
61
61
  readonly invitation: readonly ["create", "cancel"];
62
62
  }>>;
63
63
  declare const defaultRoles: {
64
- admin: Role<Subset<"member" | "organization" | "invitation", {
64
+ admin: Role<Subset<"organization" | "member" | "invitation", {
65
65
  readonly organization: readonly ["update", "delete"];
66
66
  readonly member: readonly ["create", "update", "delete"];
67
67
  readonly invitation: readonly ["create", "cancel"];
68
68
  }>>;
69
- owner: Role<Subset<"member" | "organization" | "invitation", {
69
+ owner: Role<Subset<"organization" | "member" | "invitation", {
70
70
  readonly organization: readonly ["update", "delete"];
71
71
  readonly member: readonly ["create", "update", "delete"];
72
72
  readonly invitation: readonly ["create", "cancel"];
73
73
  }>>;
74
- member: Role<Subset<"member" | "organization" | "invitation", {
74
+ member: Role<Subset<"organization" | "member" | "invitation", {
75
75
  readonly organization: readonly ["update", "delete"];
76
76
  readonly member: readonly ["create", "update", "delete"];
77
77
  readonly invitation: readonly ["create", "cancel"];
@@ -1,10 +1,11 @@
1
- import { A as Auth, a as BetterAuthOptions } from './index-CGeV0d2g.js';
2
- import 'better-call';
1
+ import { Auth } from './index.js';
2
+ import { B as BetterAuthOptions } from './internal-adapter-CVKQ4XR9.js';
3
+ import './helper-D8dhRz72.js';
3
4
  import 'zod';
4
- import './helper-B5_2Vzba.js';
5
- import './schema-BOszzrbQ.js';
6
- import 'arctic';
5
+ import 'better-call';
7
6
  import 'kysely';
7
+ import './index-CcxejJTH.js';
8
+ import 'arctic';
8
9
 
9
10
  declare const toSvelteKitHandler: (auth: Auth) => (event: {
10
11
  request: Request;
@@ -1,5 +1,6 @@
1
+ import { building } from '$app/environment';
2
+
1
3
  // src/integrations/svelte-kit.ts
2
- import { building } from "$app/environment";
3
4
  var toSvelteKitHandler = (auth) => {
4
5
  return (event) => auth.handler(event.request);
5
6
  };
@@ -20,15 +21,15 @@ var svelteKitHandler = ({
20
21
  };
21
22
  function isAuthPath(url, options) {
22
23
  const _url = new URL(url);
23
- const baseURL = new URL(options.baseURL || _url.origin);
24
- const basePath = options.basePath || "/api/auth";
24
+ const baseURL = new URL(options.baseURL || `${_url.origin}/api/auth`);
25
25
  if (_url.origin !== baseURL.origin) return false;
26
- if (!_url.pathname.startsWith(basePath)) return false;
26
+ if (!_url.pathname.startsWith(
27
+ baseURL.pathname.endsWith("/") ? baseURL.pathname : `${baseURL.pathname}/`
28
+ ))
29
+ return false;
27
30
  return true;
28
31
  }
29
- export {
30
- isAuthPath,
31
- svelteKitHandler,
32
- toSvelteKitHandler
33
- };
32
+
33
+ export { isAuthPath, svelteKitHandler, toSvelteKitHandler };
34
+ //# sourceMappingURL=svelte-kit.js.map
34
35
  //# sourceMappingURL=svelte-kit.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/integrations/svelte-kit.ts"],"sourcesContent":["//@ts-expect-error\nimport { building } from \"$app/environment\";\nimport type { Auth } from \"../auth\";\nimport type { BetterAuthOptions } from \"../types\";\n\nexport const toSvelteKitHandler = (auth: Auth) => {\n\treturn (event: { request: Request }) => auth.handler(event.request);\n};\n\nexport const svelteKitHandler = ({\n\tauth,\n\tevent,\n\tresolve,\n}: {\n\tauth: Auth;\n\tevent: { request: Request; url: URL };\n\tresolve: (event: any) => any;\n}) => {\n\tif (building) {\n\t\treturn resolve(event);\n\t}\n\tconst { request, url } = event;\n\tif (isAuthPath(url.toString(), auth.options)) {\n\t\tconsole.log(\"here\");\n\t\treturn auth.handler(request);\n\t}\n\treturn resolve(event);\n};\n\nexport function isAuthPath(url: string, options: BetterAuthOptions) {\n\tconst _url = new URL(url);\n\tconst baseURL = new URL(options.baseURL || _url.origin);\n\tconst basePath = options.basePath || \"/api/auth\";\n\tif (_url.origin !== baseURL.origin) return false;\n\tif (!_url.pathname.startsWith(basePath)) return false;\n\treturn true;\n}\n"],"mappings":";AACA,SAAS,gBAAgB;AAIlB,IAAM,qBAAqB,CAAC,SAAe;AACjD,SAAO,CAAC,UAAgC,KAAK,QAAQ,MAAM,OAAO;AACnE;AAEO,IAAM,mBAAmB,CAAC;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACD,MAIM;AACL,MAAI,UAAU;AACb,WAAO,QAAQ,KAAK;AAAA,EACrB;AACA,QAAM,EAAE,SAAS,IAAI,IAAI;AACzB,MAAI,WAAW,IAAI,SAAS,GAAG,KAAK,OAAO,GAAG;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,CAAA,OAAA,CAAQ,WAAW,CAAG,EAAA,IAAA,CAAK,MAAM,CAAW,SAAA,CAAA,CAAA,CAAA;AACpE,EAAA,IAAI,IAAK,CAAA,MAAA,KAAW,OAAQ,CAAA,MAAA,EAAe,OAAA,KAAA,CAAA;AAC3C,EACC,IAAA,CAAC,KAAK,QAAS,CAAA,UAAA;AAAA,IACd,OAAA,CAAQ,SAAS,QAAS,CAAA,GAAG,IAC1B,OAAQ,CAAA,QAAA,GACR,CAAG,EAAA,OAAA,CAAQ,QAAQ,CAAA,CAAA,CAAA;AAAA,GACvB;AAEA,IAAO,OAAA,KAAA,CAAA;AACR,EAAO,OAAA,IAAA,CAAA;AACR","file":"svelte-kit.js","sourcesContent":["//@ts-expect-error\nimport { building } from \"$app/environment\";\nimport type { Auth } from \"../auth\";\nimport type { BetterAuthOptions } from \"../types\";\n\nexport const toSvelteKitHandler = (auth: Auth) => {\n\treturn (event: { request: Request }) => auth.handler(event.request);\n};\n\nexport const svelteKitHandler = ({\n\tauth,\n\tevent,\n\tresolve,\n}: {\n\tauth: Auth;\n\tevent: { request: Request; url: URL };\n\tresolve: (event: any) => any;\n}) => {\n\tif (building) {\n\t\treturn resolve(event);\n\t}\n\tconst { request, url } = event;\n\tif (isAuthPath(url.toString(), auth.options)) {\n\t\tconsole.log(\"here\");\n\t\treturn auth.handler(request);\n\t}\n\treturn resolve(event);\n};\n\nexport function isAuthPath(url: string, options: BetterAuthOptions) {\n\tconst _url = new URL(url);\n\tconst baseURL = new URL(options.baseURL || `${_url.origin}/api/auth`);\n\tif (_url.origin !== baseURL.origin) return false;\n\tif (\n\t\t!_url.pathname.startsWith(\n\t\t\tbaseURL.pathname.endsWith(\"/\")\n\t\t\t\t? baseURL.pathname\n\t\t\t\t: `${baseURL.pathname}/`,\n\t\t)\n\t)\n\t\treturn false;\n\treturn true;\n}\n"]}