better-auth 0.2.10 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { A as Adapter } from '../index-PjYlcsPD.js';
1
+ import { A as Adapter } from '../index-L1yd6IfX.js';
2
2
  import 'kysely';
3
3
  import '../index-JM-i6hLs.js';
4
4
  import 'arctic';
@@ -1,5 +1,5 @@
1
1
  import { Db } from 'mongodb';
2
- import { W as Where } from '../index-PjYlcsPD.js';
2
+ import { W as Where } from '../index-L1yd6IfX.js';
3
3
  import 'kysely';
4
4
  import '../index-JM-i6hLs.js';
5
5
  import 'arctic';
@@ -1,4 +1,4 @@
1
- import { A as Adapter } from '../index-PjYlcsPD.js';
1
+ import { A as Adapter } from '../index-L1yd6IfX.js';
2
2
  import 'kysely';
3
3
  import '../index-JM-i6hLs.js';
4
4
  import 'arctic';
package/dist/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { e as AuthEndpoint, f as AuthMiddleware, n as callbackOAuth, L as changePassword, d as createAuthEndpoint, c as createAuthMiddleware, D as createEmailVerificationToken, V as csrfMiddleware, N as deleteUser, Q as error, y as forgetPassword, z as forgetPasswordCallback, O as getCSRFToken, l as getEndpoints, p as getSession, q as getSessionFromCtx, u as listSessions, T as ok, o as optionsMiddleware, C as resetPassword, v as revokeSession, w as revokeSessions, r as router, E as sendVerificationEmail, t as sessionMiddleware, M as setPassword, m as signInEmail, s as signInOAuth, x as signOut, U as signUpEmail, K as updateUser, J as verifyEmail } from './index-PjYlcsPD.js';
1
+ export { e as AuthEndpoint, f as AuthMiddleware, n as callbackOAuth, L as changePassword, d as createAuthEndpoint, c as createAuthMiddleware, D as createEmailVerificationToken, V as csrfMiddleware, N as deleteUser, Q as error, y as forgetPassword, z as forgetPasswordCallback, O as getCSRFToken, l as getEndpoints, p as getSession, q as getSessionFromCtx, u as listSessions, T as ok, o as optionsMiddleware, C as resetPassword, v as revokeSession, w as revokeSessions, r as router, E as sendVerificationEmail, t as sessionMiddleware, M as setPassword, m as signInEmail, s as signInOAuth, x as signOut, U as signUpEmail, K as updateUser, J as verifyEmail } from './index-L1yd6IfX.js';
2
2
  import 'zod';
3
3
  import './helper-DPDj8Nix.js';
4
4
  import 'better-call';
package/dist/api.js CHANGED
@@ -1167,10 +1167,66 @@ var verificationSchema = z5.object({
1167
1167
  identifier: z5.string()
1168
1168
  });
1169
1169
 
1170
+ // src/crypto/random.ts
1171
+ function byteToBinary(byte) {
1172
+ return byte.toString(2).padStart(8, "0");
1173
+ }
1174
+ function bytesToBinary(bytes) {
1175
+ return [...bytes].map((val) => byteToBinary(val)).join("");
1176
+ }
1177
+ function bytesToInteger(bytes) {
1178
+ return parseInt(bytesToBinary(bytes), 2);
1179
+ }
1180
+ function generateRandomInteger(max) {
1181
+ if (max < 0 || !Number.isInteger(max)) {
1182
+ throw new Error(
1183
+ "Argument 'max' must be an integer greater than or equal to 0"
1184
+ );
1185
+ }
1186
+ const bitLength = (max - 1).toString(2).length;
1187
+ const shift = bitLength % 8;
1188
+ const bytes = new Uint8Array(Math.ceil(bitLength / 8));
1189
+ crypto.getRandomValues(bytes);
1190
+ if (shift !== 0) {
1191
+ bytes[0] &= (1 << shift) - 1;
1192
+ }
1193
+ let result = bytesToInteger(bytes);
1194
+ while (result >= max) {
1195
+ crypto.getRandomValues(bytes);
1196
+ if (shift !== 0) {
1197
+ bytes[0] &= (1 << shift) - 1;
1198
+ }
1199
+ result = bytesToInteger(bytes);
1200
+ }
1201
+ return result;
1202
+ }
1203
+ function generateRandomString(length, alphabet2) {
1204
+ let result = "";
1205
+ for (let i = 0; i < length; i++) {
1206
+ result += alphabet2[generateRandomInteger(alphabet2.length)];
1207
+ }
1208
+ return result;
1209
+ }
1210
+ function alphabet(...patterns) {
1211
+ const patternSet = new Set(patterns);
1212
+ let result = "";
1213
+ for (const pattern of patternSet) {
1214
+ if (pattern === "a-z") {
1215
+ result += "abcdefghijklmnopqrstuvwxyz";
1216
+ } else if (pattern === "A-Z") {
1217
+ result += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1218
+ } else if (pattern === "0-9") {
1219
+ result += "0123456789";
1220
+ } else {
1221
+ result += pattern;
1222
+ }
1223
+ }
1224
+ return result;
1225
+ }
1226
+
1170
1227
  // src/utils/id.ts
1171
- import { nanoid } from "nanoid";
1172
1228
  var generateId = (size) => {
1173
- return nanoid(size);
1229
+ return generateRandomString(size || 21, alphabet("a-z", "0-9", "A-Z"));
1174
1230
  };
1175
1231
 
1176
1232
  // src/utils/hide-metadata.ts
@@ -1736,65 +1792,6 @@ var verifyEmail = createAuthEndpoint(
1736
1792
 
1737
1793
  // src/api/routes/update-user.ts
1738
1794
  import { z as z10 } from "zod";
1739
-
1740
- // src/crypto/random.ts
1741
- function byteToBinary(byte) {
1742
- return byte.toString(2).padStart(8, "0");
1743
- }
1744
- function bytesToBinary(bytes) {
1745
- return [...bytes].map((val) => byteToBinary(val)).join("");
1746
- }
1747
- function bytesToInteger(bytes) {
1748
- return parseInt(bytesToBinary(bytes), 2);
1749
- }
1750
- function generateRandomInteger(max) {
1751
- if (max < 0 || !Number.isInteger(max)) {
1752
- throw new Error(
1753
- "Argument 'max' must be an integer greater than or equal to 0"
1754
- );
1755
- }
1756
- const bitLength = (max - 1).toString(2).length;
1757
- const shift = bitLength % 8;
1758
- const bytes = new Uint8Array(Math.ceil(bitLength / 8));
1759
- crypto.getRandomValues(bytes);
1760
- if (shift !== 0) {
1761
- bytes[0] &= (1 << shift) - 1;
1762
- }
1763
- let result = bytesToInteger(bytes);
1764
- while (result >= max) {
1765
- crypto.getRandomValues(bytes);
1766
- if (shift !== 0) {
1767
- bytes[0] &= (1 << shift) - 1;
1768
- }
1769
- result = bytesToInteger(bytes);
1770
- }
1771
- return result;
1772
- }
1773
- function generateRandomString(length, alphabet2) {
1774
- let result = "";
1775
- for (let i = 0; i < length; i++) {
1776
- result += alphabet2[generateRandomInteger(alphabet2.length)];
1777
- }
1778
- return result;
1779
- }
1780
- function alphabet(...patterns) {
1781
- const patternSet = new Set(patterns);
1782
- let result = "";
1783
- for (const pattern of patternSet) {
1784
- if (pattern === "a-z") {
1785
- result += "abcdefghijklmnopqrstuvwxyz";
1786
- } else if (pattern === "A-Z") {
1787
- result += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1788
- } else if (pattern === "0-9") {
1789
- result += "0123456789";
1790
- } else {
1791
- result += pattern;
1792
- }
1793
- }
1794
- return result;
1795
- }
1796
-
1797
- // src/api/routes/update-user.ts
1798
1795
  var updateUser = createAuthEndpoint(
1799
1796
  "/user/update",
1800
1797
  {
@@ -2,14 +2,14 @@ import * as nanostores from 'nanostores';
2
2
  import { A as AccessControl, S as StatementsPrimitive, R as Role } from '../statement-CfnyN34h.js';
3
3
  import * as _better_fetch_fetch from '@better-fetch/fetch';
4
4
  import { BetterFetchOption } from '@better-fetch/fetch';
5
- import { o as organization, e as Organization, M as Member, I as Invitation, u as username, m as magicLink, d as phoneNumber } from '../index-CUD_IG9Z.js';
6
- export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-CUD_IG9Z.js';
5
+ import { o as organization, f as Organization, M as Member, I as Invitation, u as username, m as magicLink, d as phoneNumber, e as anonymous } from '../index-BkvPZOrg.js';
6
+ export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-BkvPZOrg.js';
7
7
  import { P as Prettify } from '../helper-DPDj8Nix.js';
8
8
  import '../index-JM-i6hLs.js';
9
9
  import 'arctic';
10
10
  import 'zod';
11
11
  import 'better-call';
12
- import '../index-PjYlcsPD.js';
12
+ import '../index-L1yd6IfX.js';
13
13
  import 'kysely';
14
14
  import 'better-sqlite3';
15
15
  import 'mysql2';
@@ -153,4 +153,12 @@ declare const phoneNumberClient: () => {
153
153
  }[];
154
154
  };
155
155
 
156
- export { magicLinkClient, organizationClient, phoneNumberClient, usernameClient };
156
+ declare const anonymousClient: () => {
157
+ id: "anonymous";
158
+ $InferServerPlugin: ReturnType<typeof anonymous>;
159
+ pathMethods: {
160
+ "/sign-in/anonymous": "POST";
161
+ };
162
+ };
163
+
164
+ export { anonymousClient, magicLinkClient, organizationClient, phoneNumberClient, usernameClient };
@@ -493,7 +493,19 @@ var phoneNumberClient = () => {
493
493
  ]
494
494
  };
495
495
  };
496
+
497
+ // src/plugins/anonymous/client.ts
498
+ var anonymousClient = () => {
499
+ return {
500
+ id: "anonymous",
501
+ $InferServerPlugin: {},
502
+ pathMethods: {
503
+ "/sign-in/anonymous": "POST"
504
+ }
505
+ };
506
+ };
496
507
  export {
508
+ anonymousClient,
497
509
  getPasskeyActions,
498
510
  magicLinkClient,
499
511
  organizationClient,
package/dist/client.d.ts CHANGED
@@ -6,7 +6,7 @@ import { BetterFetch, BetterFetchError, BetterFetchOption } from '@better-fetch/
6
6
  import { U as UnionToIntersection, P as Prettify, S as StripEmptyObjects } from './helper-DPDj8Nix.js';
7
7
  import { ClientOptions, InferClientAPI, InferActions, InferAdditionalFromClient, InferSessionFromClient, InferUserFromClient, BetterAuthClientPlugin, IsSignal } from './types.js';
8
8
  export { AtomListener, InferPluginsFromClient } from './types.js';
9
- import './index-PjYlcsPD.js';
9
+ import './index-L1yd6IfX.js';
10
10
  import 'kysely';
11
11
  import './index-JM-i6hLs.js';
12
12
  import 'arctic';
package/dist/client.js CHANGED
@@ -158,7 +158,7 @@ var getClientConfig = (options) => {
158
158
  {
159
159
  signal: "_sessionSignal",
160
160
  matcher(path) {
161
- return path === "/sign-out" || path === "sign-up/email" || path === "/user/update";
161
+ return path === "/sign-out" || path === "/user/update" || path.startsWith("/sign-in") || path.startsWith("/sign-up");
162
162
  }
163
163
  }
164
164
  ];
@@ -5,7 +5,7 @@ import { P as Prettify } from './helper-DPDj8Nix.js';
5
5
  import { A as AccessControl, R as Role, S as StatementsPrimitive, g as defaultRoles } from './statement-CfnyN34h.js';
6
6
  import * as _better_fetch_fetch from '@better-fetch/fetch';
7
7
  import { BetterFetch, BetterFetchOption } from '@better-fetch/fetch';
8
- import { H as HookEndpointContext } from './index-PjYlcsPD.js';
8
+ import { H as HookEndpointContext } from './index-L1yd6IfX.js';
9
9
  import * as nanostores from 'nanostores';
10
10
  import { atom } from 'nanostores';
11
11
  import * as _simplewebauthn_types from '@simplewebauthn/types';
@@ -4629,4 +4629,137 @@ declare const phoneNumber: (options?: {
4629
4629
  };
4630
4630
  };
4631
4631
 
4632
- export { type Invitation as I, type Member as M, type OrganizationOptions as O, type PasskeyOptions as P, twoFactorClient as a, type Passkey as b, passkeyClient as c, phoneNumber as d, type Organization as e, getPasskeyActions as g, magicLink as m, organization as o, passkey as p, twoFactor as t, username as u };
4632
+ declare const anonymous: () => {
4633
+ id: "anonymous";
4634
+ endpoints: {
4635
+ signInAnonymous: {
4636
+ (ctx_0?: better_call.Context<"/sign-in/anonymous", {
4637
+ method: "POST";
4638
+ }> | undefined): Promise<{
4639
+ user: {
4640
+ id: string;
4641
+ email: string;
4642
+ emailVerified: boolean;
4643
+ name: string;
4644
+ createdAt: Date;
4645
+ updatedAt: Date;
4646
+ image?: string | undefined;
4647
+ } & Record<string, any>;
4648
+ session: {
4649
+ id: string;
4650
+ userId: string;
4651
+ expiresAt: Date;
4652
+ ipAddress?: string | undefined;
4653
+ userAgent?: string | undefined;
4654
+ };
4655
+ } | null>;
4656
+ path: "/sign-in/anonymous";
4657
+ options: {
4658
+ method: "POST";
4659
+ };
4660
+ method: better_call.Method | better_call.Method[];
4661
+ headers: Headers;
4662
+ };
4663
+ linkAnonymous: {
4664
+ (ctx_0: better_call.Context<"/user/link-anonymous", {
4665
+ method: "POST";
4666
+ body: z.ZodObject<{
4667
+ email: z.ZodOptional<z.ZodString>;
4668
+ password: z.ZodString;
4669
+ }, "strip", z.ZodTypeAny, {
4670
+ password: string;
4671
+ email?: string | undefined;
4672
+ }, {
4673
+ password: string;
4674
+ email?: string | undefined;
4675
+ }>;
4676
+ use: better_call.Endpoint<better_call.Handler<string, better_call.EndpointOptions, {
4677
+ session: {
4678
+ session: {
4679
+ id: string;
4680
+ userId: string;
4681
+ expiresAt: Date;
4682
+ ipAddress?: string | undefined;
4683
+ userAgent?: string | undefined;
4684
+ };
4685
+ user: {
4686
+ id: string;
4687
+ email: string;
4688
+ emailVerified: boolean;
4689
+ name: string;
4690
+ createdAt: Date;
4691
+ updatedAt: Date;
4692
+ image?: string | undefined;
4693
+ };
4694
+ };
4695
+ }>, better_call.EndpointOptions>[];
4696
+ }>): Promise<{
4697
+ session: {
4698
+ id: string;
4699
+ userId: string;
4700
+ expiresAt: Date;
4701
+ ipAddress?: string | undefined;
4702
+ userAgent?: string | undefined;
4703
+ };
4704
+ user: {
4705
+ id: string;
4706
+ email: string;
4707
+ emailVerified: boolean;
4708
+ name: string;
4709
+ createdAt: Date;
4710
+ updatedAt: Date;
4711
+ image?: string | undefined;
4712
+ };
4713
+ } | null>;
4714
+ path: "/user/link-anonymous";
4715
+ options: {
4716
+ method: "POST";
4717
+ body: z.ZodObject<{
4718
+ email: z.ZodOptional<z.ZodString>;
4719
+ password: z.ZodString;
4720
+ }, "strip", z.ZodTypeAny, {
4721
+ password: string;
4722
+ email?: string | undefined;
4723
+ }, {
4724
+ password: string;
4725
+ email?: string | undefined;
4726
+ }>;
4727
+ use: better_call.Endpoint<better_call.Handler<string, better_call.EndpointOptions, {
4728
+ session: {
4729
+ session: {
4730
+ id: string;
4731
+ userId: string;
4732
+ expiresAt: Date;
4733
+ ipAddress?: string | undefined;
4734
+ userAgent?: string | undefined;
4735
+ };
4736
+ user: {
4737
+ id: string;
4738
+ email: string;
4739
+ emailVerified: boolean;
4740
+ name: string;
4741
+ createdAt: Date;
4742
+ updatedAt: Date;
4743
+ image?: string | undefined;
4744
+ };
4745
+ };
4746
+ }>, better_call.EndpointOptions>[];
4747
+ };
4748
+ method: better_call.Method | better_call.Method[];
4749
+ headers: Headers;
4750
+ };
4751
+ };
4752
+ schema: {
4753
+ user: {
4754
+ fields: {
4755
+ isAnonymous: {
4756
+ type: "boolean";
4757
+ defaultValue: true;
4758
+ required: false;
4759
+ };
4760
+ };
4761
+ };
4762
+ };
4763
+ };
4764
+
4765
+ export { type Invitation as I, type Member as M, type OrganizationOptions as O, type PasskeyOptions as P, twoFactorClient as a, type Passkey as b, passkeyClient as c, phoneNumber as d, anonymous as e, type Organization as f, getPasskeyActions as g, magicLink as m, organization as o, passkey as p, twoFactor as t, username as u };
@@ -100,7 +100,7 @@ declare const createInternalAdapter: (adapter: Adapter, ctx: {
100
100
  password?: string | null | undefined;
101
101
  } | null;
102
102
  } | null>;
103
- createUser: (user: User) => Promise<{
103
+ createUser: (user: User & Record<string, any>) => Promise<({
104
104
  id: string;
105
105
  email: string;
106
106
  emailVerified: boolean;
@@ -108,7 +108,7 @@ declare const createInternalAdapter: (adapter: Adapter, ctx: {
108
108
  createdAt: Date;
109
109
  updatedAt: Date;
110
110
  image?: string | undefined;
111
- } | null>;
111
+ } & Record<string, any>) | null>;
112
112
  deleteUser: (userId: string) => Promise<void>;
113
113
  createSession: (userId: string, request?: Request | Headers, dontRememberMe?: boolean) => Promise<{
114
114
  id: string;
@@ -2329,7 +2329,7 @@ declare const signUpEmail: {
2329
2329
  createdAt: Date;
2330
2330
  updatedAt: Date;
2331
2331
  image?: string | undefined;
2332
- };
2332
+ } & Record<string, any>;
2333
2333
  session: {
2334
2334
  id: string;
2335
2335
  userId: string;
@@ -2669,7 +2669,7 @@ declare function getEndpoints<C extends AuthContext, Option extends BetterAuthOp
2669
2669
  createdAt: Date;
2670
2670
  updatedAt: Date;
2671
2671
  image?: string | undefined;
2672
- };
2672
+ } & Record<string, any>;
2673
2673
  session: {
2674
2674
  id: string;
2675
2675
  userId: string;
@@ -3731,7 +3731,7 @@ declare const router: <C extends AuthContext, Option extends BetterAuthOptions>(
3731
3731
  createdAt: Date;
3732
3732
  updatedAt: Date;
3733
3733
  image?: string | undefined;
3734
- };
3734
+ } & Record<string, any>;
3735
3735
  session: {
3736
3736
  id: string;
3737
3737
  userId: string;
@@ -4795,7 +4795,7 @@ declare const betterAuth: <O extends BetterAuthOptions>(options: O) => {
4795
4795
  createdAt: Date;
4796
4796
  updatedAt: Date;
4797
4797
  image?: string | undefined;
4798
- };
4798
+ } & Record<string, any>;
4799
4799
  session: {
4800
4800
  id: string;
4801
4801
  userId: string;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { a as Auth, X as betterAuth } from './index-PjYlcsPD.js';
1
+ export { a as Auth, X as betterAuth } from './index-L1yd6IfX.js';
2
2
  import 'kysely';
3
3
  import './index-JM-i6hLs.js';
4
4
  import 'arctic';
package/dist/index.js CHANGED
@@ -1257,10 +1257,66 @@ var verificationSchema = z5.object({
1257
1257
  identifier: z5.string()
1258
1258
  });
1259
1259
 
1260
+ // src/crypto/random.ts
1261
+ function byteToBinary(byte) {
1262
+ return byte.toString(2).padStart(8, "0");
1263
+ }
1264
+ function bytesToBinary(bytes) {
1265
+ return [...bytes].map((val) => byteToBinary(val)).join("");
1266
+ }
1267
+ function bytesToInteger(bytes) {
1268
+ return parseInt(bytesToBinary(bytes), 2);
1269
+ }
1270
+ function generateRandomInteger(max) {
1271
+ if (max < 0 || !Number.isInteger(max)) {
1272
+ throw new Error(
1273
+ "Argument 'max' must be an integer greater than or equal to 0"
1274
+ );
1275
+ }
1276
+ const bitLength = (max - 1).toString(2).length;
1277
+ const shift = bitLength % 8;
1278
+ const bytes = new Uint8Array(Math.ceil(bitLength / 8));
1279
+ crypto.getRandomValues(bytes);
1280
+ if (shift !== 0) {
1281
+ bytes[0] &= (1 << shift) - 1;
1282
+ }
1283
+ let result = bytesToInteger(bytes);
1284
+ while (result >= max) {
1285
+ crypto.getRandomValues(bytes);
1286
+ if (shift !== 0) {
1287
+ bytes[0] &= (1 << shift) - 1;
1288
+ }
1289
+ result = bytesToInteger(bytes);
1290
+ }
1291
+ return result;
1292
+ }
1293
+ function generateRandomString(length, alphabet2) {
1294
+ let result = "";
1295
+ for (let i = 0; i < length; i++) {
1296
+ result += alphabet2[generateRandomInteger(alphabet2.length)];
1297
+ }
1298
+ return result;
1299
+ }
1300
+ function alphabet(...patterns) {
1301
+ const patternSet = new Set(patterns);
1302
+ let result = "";
1303
+ for (const pattern of patternSet) {
1304
+ if (pattern === "a-z") {
1305
+ result += "abcdefghijklmnopqrstuvwxyz";
1306
+ } else if (pattern === "A-Z") {
1307
+ result += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1308
+ } else if (pattern === "0-9") {
1309
+ result += "0123456789";
1310
+ } else {
1311
+ result += pattern;
1312
+ }
1313
+ }
1314
+ return result;
1315
+ }
1316
+
1260
1317
  // src/utils/id.ts
1261
- import { nanoid } from "nanoid";
1262
1318
  var generateId = (size) => {
1263
- return nanoid(size);
1319
+ return generateRandomString(size || 21, alphabet("a-z", "0-9", "A-Z"));
1264
1320
  };
1265
1321
 
1266
1322
  // src/utils/hide-metadata.ts
@@ -1826,65 +1882,6 @@ var verifyEmail = createAuthEndpoint(
1826
1882
 
1827
1883
  // src/api/routes/update-user.ts
1828
1884
  import { z as z10 } from "zod";
1829
-
1830
- // src/crypto/random.ts
1831
- function byteToBinary(byte) {
1832
- return byte.toString(2).padStart(8, "0");
1833
- }
1834
- function bytesToBinary(bytes) {
1835
- return [...bytes].map((val) => byteToBinary(val)).join("");
1836
- }
1837
- function bytesToInteger(bytes) {
1838
- return parseInt(bytesToBinary(bytes), 2);
1839
- }
1840
- function generateRandomInteger(max) {
1841
- if (max < 0 || !Number.isInteger(max)) {
1842
- throw new Error(
1843
- "Argument 'max' must be an integer greater than or equal to 0"
1844
- );
1845
- }
1846
- const bitLength = (max - 1).toString(2).length;
1847
- const shift = bitLength % 8;
1848
- const bytes = new Uint8Array(Math.ceil(bitLength / 8));
1849
- crypto.getRandomValues(bytes);
1850
- if (shift !== 0) {
1851
- bytes[0] &= (1 << shift) - 1;
1852
- }
1853
- let result = bytesToInteger(bytes);
1854
- while (result >= max) {
1855
- crypto.getRandomValues(bytes);
1856
- if (shift !== 0) {
1857
- bytes[0] &= (1 << shift) - 1;
1858
- }
1859
- result = bytesToInteger(bytes);
1860
- }
1861
- return result;
1862
- }
1863
- function generateRandomString(length, alphabet2) {
1864
- let result = "";
1865
- for (let i = 0; i < length; i++) {
1866
- result += alphabet2[generateRandomInteger(alphabet2.length)];
1867
- }
1868
- return result;
1869
- }
1870
- function alphabet(...patterns) {
1871
- const patternSet = new Set(patterns);
1872
- let result = "";
1873
- for (const pattern of patternSet) {
1874
- if (pattern === "a-z") {
1875
- result += "abcdefghijklmnopqrstuvwxyz";
1876
- } else if (pattern === "A-Z") {
1877
- result += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1878
- } else if (pattern === "0-9") {
1879
- result += "0123456789";
1880
- } else {
1881
- result += pattern;
1882
- }
1883
- }
1884
- return result;
1885
- }
1886
-
1887
- // src/api/routes/update-user.ts
1888
1885
  var updateUser = createAuthEndpoint(
1889
1886
  "/user/update",
1890
1887
  {
package/dist/next-js.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as Auth } from './index-PjYlcsPD.js';
1
+ import { a as Auth } from './index-L1yd6IfX.js';
2
2
  import { U as User, S as Session } from './index-JM-i6hLs.js';
3
3
  import { NextRequest } from 'next/server';
4
4
  import 'kysely';
package/dist/node.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as http from 'http';
2
- import { a as Auth } from './index-PjYlcsPD.js';
2
+ import { a as Auth } from './index-L1yd6IfX.js';
3
3
  import 'kysely';
4
4
  import './index-JM-i6hLs.js';
5
5
  import 'arctic';
package/dist/plugins.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { O as OrganizationOptions, b as Passkey, P as PasskeyOptions, g as getPasskeyActions, m as magicLink, o as organization, p as passkey, c as passkeyClient, d as phoneNumber, t as twoFactor, a as twoFactorClient, u as username } from './index-CUD_IG9Z.js';
1
+ export { O as OrganizationOptions, b as Passkey, P as PasskeyOptions, e as anonymous, g as getPasskeyActions, m as magicLink, o as organization, p as passkey, c as passkeyClient, d as phoneNumber, t as twoFactor, a as twoFactorClient, u as username } from './index-BkvPZOrg.js';
2
2
  export { i as ac } from './index-DfAHOgpj.js';
3
- import { H as HookEndpointContext } from './index-PjYlcsPD.js';
4
- export { e as AuthEndpoint, f as AuthMiddleware, b as BetterAuthPlugin, P as PluginSchema, d as createAuthEndpoint, c as createAuthMiddleware, o as optionsMiddleware } from './index-PjYlcsPD.js';
3
+ import { H as HookEndpointContext } from './index-L1yd6IfX.js';
4
+ export { e as AuthEndpoint, f as AuthMiddleware, b as BetterAuthPlugin, P as PluginSchema, d as createAuthEndpoint, c as createAuthMiddleware, o as optionsMiddleware } from './index-L1yd6IfX.js';
5
5
  import './index-JM-i6hLs.js';
6
6
  import 'arctic';
7
7
  import 'zod';
package/dist/plugins.js CHANGED
@@ -1080,10 +1080,66 @@ var verificationSchema = z4.object({
1080
1080
  identifier: z4.string()
1081
1081
  });
1082
1082
 
1083
+ // src/crypto/random.ts
1084
+ function byteToBinary(byte) {
1085
+ return byte.toString(2).padStart(8, "0");
1086
+ }
1087
+ function bytesToBinary(bytes) {
1088
+ return [...bytes].map((val) => byteToBinary(val)).join("");
1089
+ }
1090
+ function bytesToInteger(bytes) {
1091
+ return parseInt(bytesToBinary(bytes), 2);
1092
+ }
1093
+ function generateRandomInteger(max) {
1094
+ if (max < 0 || !Number.isInteger(max)) {
1095
+ throw new Error(
1096
+ "Argument 'max' must be an integer greater than or equal to 0"
1097
+ );
1098
+ }
1099
+ const bitLength = (max - 1).toString(2).length;
1100
+ const shift = bitLength % 8;
1101
+ const bytes = new Uint8Array(Math.ceil(bitLength / 8));
1102
+ crypto.getRandomValues(bytes);
1103
+ if (shift !== 0) {
1104
+ bytes[0] &= (1 << shift) - 1;
1105
+ }
1106
+ let result = bytesToInteger(bytes);
1107
+ while (result >= max) {
1108
+ crypto.getRandomValues(bytes);
1109
+ if (shift !== 0) {
1110
+ bytes[0] &= (1 << shift) - 1;
1111
+ }
1112
+ result = bytesToInteger(bytes);
1113
+ }
1114
+ return result;
1115
+ }
1116
+ function generateRandomString(length, alphabet2) {
1117
+ let result = "";
1118
+ for (let i = 0; i < length; i++) {
1119
+ result += alphabet2[generateRandomInteger(alphabet2.length)];
1120
+ }
1121
+ return result;
1122
+ }
1123
+ function alphabet(...patterns) {
1124
+ const patternSet = new Set(patterns);
1125
+ let result = "";
1126
+ for (const pattern of patternSet) {
1127
+ if (pattern === "a-z") {
1128
+ result += "abcdefghijklmnopqrstuvwxyz";
1129
+ } else if (pattern === "A-Z") {
1130
+ result += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1131
+ } else if (pattern === "0-9") {
1132
+ result += "0123456789";
1133
+ } else {
1134
+ result += pattern;
1135
+ }
1136
+ }
1137
+ return result;
1138
+ }
1139
+
1083
1140
  // src/utils/id.ts
1084
- import { nanoid } from "nanoid";
1085
1141
  var generateId = (size) => {
1086
- return nanoid(size);
1142
+ return generateRandomString(size || 21, alphabet("a-z", "0-9", "A-Z"));
1087
1143
  };
1088
1144
 
1089
1145
  // src/utils/hide-metadata.ts
@@ -1649,65 +1705,6 @@ var verifyEmail = createAuthEndpoint(
1649
1705
 
1650
1706
  // src/api/routes/update-user.ts
1651
1707
  import { z as z9 } from "zod";
1652
-
1653
- // src/crypto/random.ts
1654
- function byteToBinary(byte) {
1655
- return byte.toString(2).padStart(8, "0");
1656
- }
1657
- function bytesToBinary(bytes) {
1658
- return [...bytes].map((val) => byteToBinary(val)).join("");
1659
- }
1660
- function bytesToInteger(bytes) {
1661
- return parseInt(bytesToBinary(bytes), 2);
1662
- }
1663
- function generateRandomInteger(max) {
1664
- if (max < 0 || !Number.isInteger(max)) {
1665
- throw new Error(
1666
- "Argument 'max' must be an integer greater than or equal to 0"
1667
- );
1668
- }
1669
- const bitLength = (max - 1).toString(2).length;
1670
- const shift = bitLength % 8;
1671
- const bytes = new Uint8Array(Math.ceil(bitLength / 8));
1672
- crypto.getRandomValues(bytes);
1673
- if (shift !== 0) {
1674
- bytes[0] &= (1 << shift) - 1;
1675
- }
1676
- let result = bytesToInteger(bytes);
1677
- while (result >= max) {
1678
- crypto.getRandomValues(bytes);
1679
- if (shift !== 0) {
1680
- bytes[0] &= (1 << shift) - 1;
1681
- }
1682
- result = bytesToInteger(bytes);
1683
- }
1684
- return result;
1685
- }
1686
- function generateRandomString(length, alphabet2) {
1687
- let result = "";
1688
- for (let i = 0; i < length; i++) {
1689
- result += alphabet2[generateRandomInteger(alphabet2.length)];
1690
- }
1691
- return result;
1692
- }
1693
- function alphabet(...patterns) {
1694
- const patternSet = new Set(patterns);
1695
- let result = "";
1696
- for (const pattern of patternSet) {
1697
- if (pattern === "a-z") {
1698
- result += "abcdefghijklmnopqrstuvwxyz";
1699
- } else if (pattern === "A-Z") {
1700
- result += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1701
- } else if (pattern === "0-9") {
1702
- result += "0123456789";
1703
- } else {
1704
- result += pattern;
1705
- }
1706
- }
1707
- return result;
1708
- }
1709
-
1710
- // src/api/routes/update-user.ts
1711
1708
  var updateUser = createAuthEndpoint(
1712
1709
  "/user/update",
1713
1710
  {
@@ -6139,9 +6136,133 @@ var phoneNumber = (options) => {
6139
6136
  }
6140
6137
  };
6141
6138
  };
6139
+
6140
+ // src/plugins/anonymous/index.ts
6141
+ import { z as z26 } from "zod";
6142
+ var anonymous = () => {
6143
+ return {
6144
+ id: "anonymous",
6145
+ endpoints: {
6146
+ signInAnonymous: createAuthEndpoint(
6147
+ "/sign-in/anonymous",
6148
+ {
6149
+ method: "POST"
6150
+ },
6151
+ async (ctx) => {
6152
+ const tempEmail = "temporary-" + Date.now().toString() + "-better-auth@email.com";
6153
+ const newUser = await ctx.context.internalAdapter.createUser({
6154
+ id: generateId(),
6155
+ email: tempEmail,
6156
+ emailVerified: false,
6157
+ isAnonymous: true,
6158
+ name: "Anonymous",
6159
+ createdAt: /* @__PURE__ */ new Date(),
6160
+ updatedAt: /* @__PURE__ */ new Date()
6161
+ });
6162
+ if (!newUser) {
6163
+ return ctx.json(null, {
6164
+ status: 500,
6165
+ body: {
6166
+ message: "Failed to create user",
6167
+ status: 500
6168
+ }
6169
+ });
6170
+ }
6171
+ const session = await ctx.context.internalAdapter.createSession(
6172
+ newUser.id,
6173
+ ctx.request
6174
+ );
6175
+ if (!session) {
6176
+ return ctx.json(null, {
6177
+ status: 400,
6178
+ body: {
6179
+ message: "Could not create session"
6180
+ }
6181
+ });
6182
+ }
6183
+ await setSessionCookie(ctx, session.id);
6184
+ return ctx.json({ user: newUser, session });
6185
+ }
6186
+ ),
6187
+ linkAnonymous: createAuthEndpoint(
6188
+ "/user/link-anonymous",
6189
+ {
6190
+ method: "POST",
6191
+ body: z26.object({
6192
+ email: z26.string().email().optional(),
6193
+ password: z26.string().min(6)
6194
+ }),
6195
+ use: [sessionMiddleware]
6196
+ },
6197
+ async (ctx) => {
6198
+ const userId = ctx.context.session.user.id;
6199
+ const { email, password } = ctx.body;
6200
+ let updatedUser = null;
6201
+ if (email && password) {
6202
+ updatedUser = await ctx.context.internalAdapter.updateUser(userId, {
6203
+ email
6204
+ });
6205
+ }
6206
+ if (!updatedUser) {
6207
+ return ctx.json(null, {
6208
+ status: 500,
6209
+ body: {
6210
+ message: "Failed to update user",
6211
+ status: 500
6212
+ }
6213
+ });
6214
+ }
6215
+ const hash = await ctx.context.password.hash(password);
6216
+ const updateUserAccount = await ctx.context.internalAdapter.linkAccount({
6217
+ id: generateRandomString(32, alphabet("a-z", "0-9", "A-Z")),
6218
+ userId: updatedUser.id,
6219
+ providerId: "credential",
6220
+ password: hash,
6221
+ accountId: updatedUser.id
6222
+ });
6223
+ if (!updateUserAccount) {
6224
+ return ctx.json(null, {
6225
+ status: 500,
6226
+ body: {
6227
+ message: "Failed to update account",
6228
+ status: 500
6229
+ }
6230
+ });
6231
+ }
6232
+ const session = await ctx.context.internalAdapter.createSession(
6233
+ updatedUser.id,
6234
+ ctx.request
6235
+ );
6236
+ if (!session) {
6237
+ return ctx.json(null, {
6238
+ status: 400,
6239
+ body: {
6240
+ message: "Could not create session"
6241
+ }
6242
+ });
6243
+ }
6244
+ await setSessionCookie(ctx, session.id);
6245
+ return ctx.json({ session, user: updatedUser });
6246
+ }
6247
+ )
6248
+ },
6249
+ schema: {
6250
+ user: {
6251
+ fields: {
6252
+ isAnonymous: {
6253
+ type: "boolean",
6254
+ defaultValue: true,
6255
+ required: false
6256
+ }
6257
+ }
6258
+ }
6259
+ }
6260
+ };
6261
+ };
6142
6262
  export {
6143
6263
  HIDE_METADATA,
6144
6264
  access_exports as ac,
6265
+ anonymous,
6145
6266
  bearer,
6146
6267
  createAuthEndpoint,
6147
6268
  createAuthMiddleware,
package/dist/react.d.ts CHANGED
@@ -3,7 +3,7 @@ import { U as UnionToIntersection, P as Prettify, S as StripEmptyObjects } from
3
3
  import { ClientOptions, InferClientAPI, InferActions, InferAdditionalFromClient, BetterAuthClientPlugin, IsSignal } from './types.js';
4
4
  import { useStore } from '@nanostores/react';
5
5
  import 'zod';
6
- import './index-PjYlcsPD.js';
6
+ import './index-L1yd6IfX.js';
7
7
  import 'kysely';
8
8
  import './index-JM-i6hLs.js';
9
9
  import 'arctic';
package/dist/react.js CHANGED
@@ -161,7 +161,7 @@ var getClientConfig = (options) => {
161
161
  {
162
162
  signal: "_sessionSignal",
163
163
  matcher(path) {
164
- return path === "/sign-out" || path === "sign-up/email" || path === "/user/update";
164
+ return path === "/sign-out" || path === "/user/update" || path.startsWith("/sign-in") || path.startsWith("/sign-up");
165
165
  }
166
166
  }
167
167
  ];
@@ -1,4 +1,4 @@
1
- import { a as Auth } from './index-PjYlcsPD.js';
1
+ import { a as Auth } from './index-L1yd6IfX.js';
2
2
  import 'kysely';
3
3
  import './index-JM-i6hLs.js';
4
4
  import 'arctic';
package/dist/solid.d.ts CHANGED
@@ -3,7 +3,7 @@ import { U as UnionToIntersection, P as Prettify, S as StripEmptyObjects } from
3
3
  import { ClientOptions, InferClientAPI, InferActions, InferAdditionalFromClient, BetterAuthClientPlugin, IsSignal } from './types.js';
4
4
  import { Accessor } from 'solid-js';
5
5
  import 'zod';
6
- import './index-PjYlcsPD.js';
6
+ import './index-L1yd6IfX.js';
7
7
  import 'kysely';
8
8
  import './index-JM-i6hLs.js';
9
9
  import 'arctic';
package/dist/solid.js CHANGED
@@ -161,7 +161,7 @@ var getClientConfig = (options) => {
161
161
  {
162
162
  signal: "_sessionSignal",
163
163
  matcher(path) {
164
- return path === "/sign-out" || path === "sign-up/email" || path === "/user/update";
164
+ return path === "/sign-out" || path === "/user/update" || path.startsWith("/sign-in") || path.startsWith("/sign-up");
165
165
  }
166
166
  }
167
167
  ];
@@ -1,4 +1,4 @@
1
- import { a as Auth, B as BetterAuthOptions } from './index-PjYlcsPD.js';
1
+ import { a as Auth, B as BetterAuthOptions } from './index-L1yd6IfX.js';
2
2
  import 'kysely';
3
3
  import './index-JM-i6hLs.js';
4
4
  import 'arctic';
package/dist/svelte.d.ts CHANGED
@@ -3,7 +3,7 @@ import * as _better_fetch_fetch from '@better-fetch/fetch';
3
3
  import { U as UnionToIntersection, P as Prettify, S as StripEmptyObjects } from './helper-DPDj8Nix.js';
4
4
  import { ClientOptions, InferClientAPI, InferActions, InferAdditionalFromClient, BetterAuthClientPlugin, IsSignal } from './types.js';
5
5
  import 'zod';
6
- import './index-PjYlcsPD.js';
6
+ import './index-L1yd6IfX.js';
7
7
  import 'kysely';
8
8
  import './index-JM-i6hLs.js';
9
9
  import 'arctic';
package/dist/svelte.js CHANGED
@@ -158,7 +158,7 @@ var getClientConfig = (options) => {
158
158
  {
159
159
  signal: "_sessionSignal",
160
160
  matcher(path) {
161
- return path === "/sign-out" || path === "sign-up/email" || path === "/user/update";
161
+ return path === "/sign-out" || path === "/user/update" || path.startsWith("/sign-in") || path.startsWith("/sign-up");
162
162
  }
163
163
  }
164
164
  ];
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { b as BetterAuthPlugin, a as Auth, F as FieldAttribute, I as InferFieldOutput } from './index-PjYlcsPD.js';
2
- export { A as Adapter, k as AuthContext, B as BetterAuthOptions, G as GenericEndpointContext, H as HookEndpointContext, i as InferPluginTypes, h as InferSession, g as InferUser, P as PluginSchema, R as RateLimit, S as SessionAdapter, W as Where, j as init } from './index-PjYlcsPD.js';
1
+ import { b as BetterAuthPlugin, a as Auth, F as FieldAttribute, I as InferFieldOutput } from './index-L1yd6IfX.js';
2
+ export { A as Adapter, k as AuthContext, B as BetterAuthOptions, G as GenericEndpointContext, H as HookEndpointContext, i as InferPluginTypes, h as InferSession, g as InferUser, P as PluginSchema, R as RateLimit, S as SessionAdapter, W as Where, j as init } from './index-L1yd6IfX.js';
3
3
  import { U as UnionToIntersection, H as HasRequiredKeys, P as Prettify, S as StripEmptyObjects, L as LiteralString } from './helper-DPDj8Nix.js';
4
4
  export { D as DeepPartial, a as LiteralUnion, R as RequiredKeysOf, W as WithoutEmpty } from './helper-DPDj8Nix.js';
5
5
  import { S as Session, U as User } from './index-JM-i6hLs.js';
package/dist/vue.d.ts CHANGED
@@ -3,7 +3,7 @@ import { U as UnionToIntersection, P as Prettify, S as StripEmptyObjects } from
3
3
  import { ClientOptions, InferClientAPI, InferActions, InferAdditionalFromClient, BetterAuthClientPlugin, IsSignal } from './types.js';
4
4
  import { Ref, DeepReadonly } from 'vue';
5
5
  import 'zod';
6
- import './index-PjYlcsPD.js';
6
+ import './index-L1yd6IfX.js';
7
7
  import 'kysely';
8
8
  import './index-JM-i6hLs.js';
9
9
  import 'arctic';
package/dist/vue.js CHANGED
@@ -161,7 +161,7 @@ var getClientConfig = (options) => {
161
161
  {
162
162
  signal: "_sessionSignal",
163
163
  matcher(path) {
164
- return path === "/sign-out" || path === "sign-up/email" || path === "/user/update";
164
+ return path === "/sign-out" || path === "/user/update" || path.startsWith("/sign-in") || path.startsWith("/sign-up");
165
165
  }
166
166
  }
167
167
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-auth",
3
- "version": "0.2.10",
3
+ "version": "0.3.0",
4
4
  "description": "The most comprehensive authentication library for TypeScript.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",