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/vue.js CHANGED
@@ -1,15 +1,8 @@
1
- // src/client/vue.ts
2
- import { useStore } from "@nanostores/vue";
3
-
4
- // src/client/base.ts
5
- import { createFetch } from "@better-fetch/fetch";
1
+ import { useStore } from '@nanostores/vue';
2
+ import { createFetch, betterFetch } from '@better-fetch/fetch';
3
+ import { atom, computed, task } from 'nanostores';
6
4
 
7
- // src/error/better-auth-error.ts
8
- var BetterAuthError = class extends Error {
9
- constructor(message) {
10
- super(message);
11
- }
12
- };
5
+ // src/client/vue.ts
13
6
 
14
7
  // src/utils/base-url.ts
15
8
  function checkHasPath(url) {
@@ -24,47 +17,43 @@ function checkHasPath(url) {
24
17
  function withPath(url, path = "/api/auth") {
25
18
  const hasPath = checkHasPath(url);
26
19
  if (hasPath) {
27
- return {
28
- baseURL: new URL(url).origin,
29
- withPath: url
30
- };
20
+ return url;
31
21
  }
32
22
  path = path.startsWith("/") ? path : `/${path}`;
33
- return {
34
- baseURL: url,
35
- withPath: `${url}${path}`
36
- };
23
+ return `${url}${path}`;
37
24
  }
38
25
  function getBaseURL(url, path) {
39
26
  if (url) {
40
27
  return withPath(url, path);
41
28
  }
42
29
  const env = typeof process !== "undefined" ? process.env : {};
43
- 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;
44
31
  if (fromEnv) {
45
32
  return withPath(fromEnv, path);
46
33
  }
47
- const isDev = !fromEnv && (env.NODE_ENV === "development" || env.NODE_ENV === "test");
48
- if (isDev) {
49
- return {
50
- baseURL: "http://localhost:3000",
51
- withPath: "http://localhost:3000/api/auth"
52
- };
34
+ if (typeof window !== "undefined") {
35
+ return withPath(window.location.origin, path);
53
36
  }
54
- throw new BetterAuthError(
55
- "Could not infer baseURL from environment variables"
56
- );
37
+ return void 0;
57
38
  }
58
39
 
40
+ // src/error/better-auth-error.ts
41
+ var BetterAuthError = class extends Error {
42
+ constructor(message) {
43
+ super(message);
44
+ }
45
+ };
46
+
59
47
  // src/client/fetch-plugins.ts
60
- import { betterFetch } from "@better-fetch/fetch";
61
48
  var redirectPlugin = {
62
49
  id: "redirect",
63
50
  name: "Redirect",
64
51
  hooks: {
65
52
  onSuccess(context) {
66
53
  if (context.data?.url && context.data?.redirect) {
67
- window.location.href = context.data.url;
54
+ if (typeof window !== "undefined") {
55
+ window.location.href = context.data.url;
56
+ }
68
57
  }
69
58
  }
70
59
  }
@@ -87,6 +76,17 @@ var csrfPlugin = {
87
76
  id: "csrf",
88
77
  name: "CSRF Check",
89
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
+ }
90
90
  if (options?.method !== "GET") {
91
91
  options = options || {};
92
92
  const { data, error } = await betterFetch("/csrf", {
@@ -94,7 +94,8 @@ var csrfPlugin = {
94
94
  baseURL: options.baseURL,
95
95
  plugins: [],
96
96
  method: "GET",
97
- credentials: "include"
97
+ credentials: "include",
98
+ customFetchImpl: options.customFetchImpl
98
99
  });
99
100
  if (error?.status === 404) {
100
101
  throw new BetterAuthError(
@@ -114,6 +115,61 @@ var csrfPlugin = {
114
115
  }
115
116
  };
116
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
+
168
+ // src/utils/misc.ts
169
+ function capitalizeFirstLetter(str) {
170
+ return str.charAt(0).toUpperCase() + str.slice(1);
171
+ }
172
+
117
173
  // src/client/proxy.ts
118
174
  function getMethod(path, knownPathMethods, args) {
119
175
  const method = knownPathMethods[path];
@@ -129,7 +185,7 @@ function getMethod(path, knownPathMethods, args) {
129
185
  }
130
186
  return "GET";
131
187
  }
132
- function createDynamicPathProxy(routes, client, knownPathMethods, $signal, $signals) {
188
+ function createDynamicPathProxy(routes, client, knownPathMethods, atoms, atomListeners) {
133
189
  function createProxy(path = []) {
134
190
  return new Proxy(function() {
135
191
  }, {
@@ -158,16 +214,21 @@ function createDynamicPathProxy(routes, client, knownPathMethods, $signal, $sign
158
214
  const { query, options, ...body } = arg;
159
215
  return await client(routePath, {
160
216
  ...options,
161
- body: method === "GET" ? void 0 : body,
217
+ body: method === "GET" ? void 0 : {
218
+ ...body,
219
+ ...options?.body || {}
220
+ },
162
221
  query,
163
222
  method,
164
223
  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
224
  await options?.onSuccess?.(context);
225
+ const matches = atomListeners?.find((s) => s.matcher(routePath));
226
+ if (!matches) return;
227
+ const signal = atoms[matches.signal];
228
+ if (!signal) return;
229
+ setTimeout(() => {
230
+ signal.set(!signal.get());
231
+ }, 0);
171
232
  }
172
233
  });
173
234
  }
@@ -175,9 +236,6 @@ function createDynamicPathProxy(routes, client, knownPathMethods, $signal, $sign
175
236
  }
176
237
  return createProxy();
177
238
  }
178
-
179
- // src/client/session-atom.ts
180
- import { atom, computed, task } from "nanostores";
181
239
  function getSessionAtom(client) {
182
240
  const $signal = atom(false);
183
241
  const $session = computed(
@@ -190,119 +248,47 @@ function getSessionAtom(client) {
190
248
  return session.data;
191
249
  })
192
250
  );
193
- return { $session, $sessionSignal: $signal };
251
+ return { $session, _sessionSignal: $signal };
194
252
  }
195
253
 
196
- // src/client/base.ts
197
- var createAuthFetch = (options) => {
198
- const $baseFetch = createFetch();
199
- return createFetch({
200
- method: "GET",
201
- ...options,
202
- baseURL: getBaseURL(options?.baseURL).withPath,
203
- plugins: [
204
- ...options?.plugins || [],
205
- ...options?.authPlugins?.flatMap((plugin) => plugin($baseFetch).fetchPlugins).filter((plugin) => plugin !== void 0) || [],
206
- ...options?.csrfPlugin !== false ? [csrfPlugin] : [],
207
- redirectPlugin,
208
- addCurrentURL
209
- ]
210
- });
211
- };
212
- var createAuthClient = (options, additionalActions = {}) => {
213
- const $fetch = createAuthFetch(options);
214
- const { $session, $sessionSignal } = getSessionAtom($fetch);
215
- let pluginsActions = {};
216
- const pluginProxySignals = [];
217
- let pluginSignals = {};
218
- let pluginPathMethods = {};
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
- };
241
- }
242
- }
243
- const actions = {
244
- $atoms: {
245
- $session
246
- },
254
+ // src/client/vue.ts
255
+ function getAtomKey(str) {
256
+ return `use${capitalizeFirstLetter(str)}`;
257
+ }
258
+ function createAuthClient(options) {
259
+ const {
260
+ pluginPathMethods,
261
+ pluginsActions,
262
+ pluginsAtoms,
247
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 = {
248
275
  ...pluginsActions,
249
- ...additionalActions
276
+ ...resolvedHooks,
277
+ useSession
250
278
  };
251
279
  const proxy = createDynamicPathProxy(
252
- actions,
280
+ routes,
253
281
  $fetch,
282
+ pluginPathMethods,
254
283
  {
255
- ...pluginPathMethods,
256
- "/sign-out": "POST"
284
+ ...pluginsAtoms,
285
+ _sessionSignal
257
286
  },
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
- }
287
+ atomListeners
277
288
  );
278
289
  return proxy;
279
- };
290
+ }
280
291
 
281
- // src/client/vue.ts
282
- var createAuthClient2 = (options) => {
283
- const $fetch = createAuthFetch(options);
284
- const hooks = options?.authPlugins?.reduce(
285
- (acc, plugin) => {
286
- return {
287
- ...acc,
288
- ...plugin($fetch).integrations?.vue?.(useStore) || {}
289
- };
290
- },
291
- {}
292
- );
293
- const client = createAuthClient(options, hooks);
294
- function useSession() {
295
- return useStore(client.$atoms.$session);
296
- }
297
- const obj = Object.assign(client, {
298
- useSession,
299
- ...hooks
300
- });
301
- return obj;
302
- };
303
- var useAuthStore = useStore;
304
- export {
305
- createAuthClient2 as createAuthClient,
306
- useAuthStore
307
- };
292
+ export { createAuthClient };
293
+ //# sourceMappingURL=vue.js.map
308
294
  //# sourceMappingURL=vue.js.map
package/dist/vue.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client/vue.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/vue\";\nimport { createAuthFetch, createAuthClient as createClient } from \"./base\";\nimport type { AuthPlugin, ClientOptions } from \"./type\";\nimport type { UnionToIntersection } from \"../types/helper\";\n\nexport const createAuthClient = <O extends ClientOptions>(options?: O) => {\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?.vue?.(useStore) || {}),\n\t\t\t};\n\t\t},\n\t\t{} as Record<string, any>,\n\t) as O[\"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\tvue?: (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\tconst client = createClient(options, hooks);\n\tfunction useSession() {\n\t\treturn useStore(client.$atoms.$session);\n\t}\n\tconst obj = Object.assign(client, {\n\t\tuseSession,\n\t\t...hooks,\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,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;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tJO,IAAMA,oBAAmB,CAA0B,YAAgB;AACzE,QAAM,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,MAAM,QAAQ,KAAK,CAAC;AAAA,MACtD;AAAA,IACD;AAAA,IACA,CAAC;AAAA,EACF;AAaA,QAAM,SAAS,iBAAa,SAAS,KAAK;AAC1C,WAAS,aAAa;AACrB,WAAO,SAAS,OAAO,OAAO,QAAQ;AAAA,EACvC;AACA,QAAM,MAAM,OAAO,OAAO,QAAQ;AAAA,IACjC;AAAA,IACA,GAAG;AAAA,EACJ,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/vue.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,GA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,GAAK,EAAA,KAAK,KAAK,MAAO,CAAA,OAAA,CAAQ,YAAY,CAAG,EAAA;AACxD,IAAA,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;AAEA,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":"vue.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/vue\";\nimport type { DeepReadonly, Ref } from \"vue\";\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\";\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]: () => DeepReadonly<\n\t\t\t\t\t\t\tRef<ReturnType<Atoms[key][\"get\"]>>\n\t\t\t\t\t\t>;\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\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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-auth",
3
- "version": "0.0.8-beta.2",
3
+ "version": "0.0.8-beta.21",
4
4
  "description": "Framework-agnostic, batteries included authentication library for typescript",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -43,18 +43,20 @@
43
43
  "@types/prompts": "^2.4.9",
44
44
  "@types/react": "^18.3.3",
45
45
  "h3": "^1.12.0",
46
+ "happy-dom": "^15.7.3",
46
47
  "hono": "^4.5.4",
47
48
  "listhen": "^1.7.2",
49
+ "next": "^14.2.8",
48
50
  "react": "^18.3.1",
49
51
  "solid-js": "^1.8.18",
50
52
  "swr": "^2.2.5",
51
53
  "tsup": "^8.2.4",
52
54
  "typescript": "5.6.0-beta",
53
- "vitest": "^1.6.0"
55
+ "vitest": "^1.6.0",
56
+ "vue": "^3.5.0"
54
57
  },
55
58
  "dependencies": {
56
59
  "@better-fetch/fetch": "^1.1.4",
57
- "better-sqlite3": "^11.1.2",
58
60
  "@better-fetch/logger": "^1.1.3",
59
61
  "@chronark/access-policies": "^0.0.2",
60
62
  "@nanostores/query": "^0.3.4",
@@ -67,10 +69,13 @@
67
69
  "@simplewebauthn/browser": "^10.0.0",
68
70
  "@simplewebauthn/server": "^10.0.1",
69
71
  "arctic": "2.0.0-next.5",
72
+ "argon2": "^0.41.1",
70
73
  "better-call": "^0.1.38",
74
+ "better-sqlite3": "^11.1.2",
71
75
  "chalk": "^5.3.0",
72
76
  "commander": "^12.1.0",
73
77
  "consola": "^3.2.3",
78
+ "defu": "^6.1.4",
74
79
  "dotenv": "^16.4.5",
75
80
  "jiti": "^1.21.6",
76
81
  "jose": "^5.7.0",