better-auth 0.4.4 → 0.4.6

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-Bt0CUdx4.js';
1
+ import { A as Adapter } from '../index-BJKlHmT9.js';
2
2
  import 'zod';
3
3
  import 'kysely';
4
4
  import '../types-IzAbV4nB.js';
@@ -41,8 +41,6 @@ var getAuthTables = (options) => {
41
41
  }
42
42
  };
43
43
  const { user, session, account, ...pluginTables } = pluginSchema || {};
44
- const accountFields = options.account?.fields;
45
- const userFields = options.user?.fields;
46
44
  return {
47
45
  user: {
48
46
  tableName: options.user?.modelName || "user",
@@ -84,7 +82,7 @@ var getAuthTables = (options) => {
84
82
  ...user?.fields,
85
83
  ...options.user?.additionalFields
86
84
  },
87
- order: 0
85
+ order: 1
88
86
  },
89
87
  session: {
90
88
  tableName: options.session?.modelName || "session",
@@ -117,7 +115,7 @@ var getAuthTables = (options) => {
117
115
  ...session?.fields,
118
116
  ...options.session?.additionalFields
119
117
  },
120
- order: 1
118
+ order: 2
121
119
  },
122
120
  account: {
123
121
  tableName: options.account?.modelName || "account",
@@ -169,7 +167,7 @@ var getAuthTables = (options) => {
169
167
  },
170
168
  ...account?.fields
171
169
  },
172
- order: 2
170
+ order: 3
173
171
  },
174
172
  verification: {
175
173
  tableName: options.verification?.modelName || "verification",
@@ -189,7 +187,8 @@ var getAuthTables = (options) => {
189
187
  required: true,
190
188
  fieldName: options.verification?.fields?.expiresAt || "expiresAt"
191
189
  }
192
- }
190
+ },
191
+ order: 4
193
192
  },
194
193
  ...pluginTables,
195
194
  ...shouldAddRateLimitTable ? rateLimitTable : {}
@@ -1,5 +1,5 @@
1
1
  import { Db } from 'mongodb';
2
- import { W as Where } from '../index-Bt0CUdx4.js';
2
+ import { W as Where } from '../index-BJKlHmT9.js';
3
3
  import 'zod';
4
4
  import 'kysely';
5
5
  import '../types-IzAbV4nB.js';
@@ -1,4 +1,4 @@
1
- import { A as Adapter } from '../index-Bt0CUdx4.js';
1
+ import { A as Adapter } from '../index-BJKlHmT9.js';
2
2
  import 'zod';
3
3
  import 'kysely';
4
4
  import '../types-IzAbV4nB.js';
package/dist/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { e as AuthEndpoint, f as AuthMiddleware, v as callbackOAuth, T as changePassword, d as createAuthEndpoint, c as createAuthMiddleware, M as createEmailVerificationToken, $ as csrfMiddleware, V as deleteUser, Y as error, J as forgetPassword, K as forgetPasswordCallback, X as getCSRFToken, r as getEndpoints, w as getSession, x as getSessionFromCtx, z as listSessions, Z as ok, o as optionsMiddleware, L as resetPassword, C as revokeSession, D as revokeSessions, s as router, N as sendVerificationEmail, y as sessionMiddleware, U as setPassword, u as signInEmail, t as signInOAuth, E as signOut, _ as signUpEmail, Q as updateUser, O as verifyEmail } from './index-Bt0CUdx4.js';
1
+ export { e as AuthEndpoint, f as AuthMiddleware, v as callbackOAuth, T as changePassword, d as createAuthEndpoint, c as createAuthMiddleware, M as createEmailVerificationToken, $ as csrfMiddleware, V as deleteUser, Y as error, J as forgetPassword, K as forgetPasswordCallback, X as getCSRFToken, r as getEndpoints, w as getSession, x as getSessionFromCtx, z as listSessions, Z as ok, o as optionsMiddleware, L as resetPassword, C as revokeSession, D as revokeSessions, s as router, N as sendVerificationEmail, y as sessionMiddleware, U as setPassword, u as signInEmail, t as signInOAuth, E as signOut, _ as signUpEmail, Q as updateUser, O as verifyEmail } from './index-BJKlHmT9.js';
2
2
  import './helper-DPDj8Nix.js';
3
3
  import 'zod';
4
4
  export { APIError } from 'better-call';
package/dist/api.js CHANGED
@@ -1040,39 +1040,39 @@ var signInOAuth = createAuthEndpoint(
1040
1040
  provider: z4.enum(oAuthProviderList)
1041
1041
  })
1042
1042
  },
1043
- async (c) => {
1044
- const provider = c.context.socialProviders.find(
1045
- (p) => p.id === c.body.provider
1043
+ async (c2) => {
1044
+ const provider = c2.context.socialProviders.find(
1045
+ (p) => p.id === c2.body.provider
1046
1046
  );
1047
1047
  if (!provider) {
1048
- c.context.logger.error(
1048
+ c2.context.logger.error(
1049
1049
  "Provider not found. Make sure to add the provider to your auth config",
1050
1050
  {
1051
- provider: c.body.provider
1051
+ provider: c2.body.provider
1052
1052
  }
1053
1053
  );
1054
1054
  throw new APIError3("NOT_FOUND", {
1055
1055
  message: "Provider not found"
1056
1056
  });
1057
1057
  }
1058
- const cookie = c.context.authCookies;
1059
- const currentURL = c.query?.currentURL ? new URL(c.query?.currentURL) : null;
1060
- const callbackURL = c.body.callbackURL?.startsWith("http") ? c.body.callbackURL : `${currentURL?.origin}${c.body.callbackURL || ""}`;
1058
+ const cookie = c2.context.authCookies;
1059
+ const currentURL = c2.query?.currentURL ? new URL(c2.query?.currentURL) : null;
1060
+ const callbackURL = c2.body.callbackURL?.startsWith("http") ? c2.body.callbackURL : `${currentURL?.origin}${c2.body.callbackURL || ""}`;
1061
1061
  const state = generateState(
1062
- callbackURL || currentURL?.origin || c.context.baseURL,
1063
- c.query?.currentURL
1062
+ callbackURL || currentURL?.origin || c2.context.baseURL,
1063
+ c2.query?.currentURL
1064
1064
  );
1065
- await c.setSignedCookie(
1065
+ await c2.setSignedCookie(
1066
1066
  cookie.state.name,
1067
1067
  state.code,
1068
- c.context.secret,
1068
+ c2.context.secret,
1069
1069
  cookie.state.options
1070
1070
  );
1071
1071
  const codeVerifier = generateCodeVerifier();
1072
- await c.setSignedCookie(
1072
+ await c2.setSignedCookie(
1073
1073
  cookie.pkCodeVerifier.name,
1074
1074
  codeVerifier,
1075
- c.context.secret,
1075
+ c2.context.secret,
1076
1076
  cookie.pkCodeVerifier.options
1077
1077
  );
1078
1078
  const url = await provider.createAuthorizationURL({
@@ -1081,9 +1081,9 @@ var signInOAuth = createAuthEndpoint(
1081
1081
  });
1082
1082
  url.searchParams.set(
1083
1083
  "redirect_uri",
1084
- `${c.context.baseURL}/callback/${c.body.provider}`
1084
+ `${c2.context.baseURL}/callback/${c2.body.provider}`
1085
1085
  );
1086
- return c.json({
1086
+ return c2.json({
1087
1087
  url: url.toString(),
1088
1088
  state: state.state,
1089
1089
  codeVerifier,
@@ -1128,7 +1128,9 @@ var signInEmail = createAuthEndpoint(
1128
1128
  message: "Invalid email"
1129
1129
  });
1130
1130
  }
1131
- const user = await ctx.context.internalAdapter.findUserByEmail(email);
1131
+ const user = await ctx.context.internalAdapter.findUserByEmail(email, {
1132
+ includeAccounts: true
1133
+ });
1132
1134
  if (!user) {
1133
1135
  await ctx.context.password.hash(password);
1134
1136
  ctx.context.logger.error("User not found", { email });
@@ -1182,6 +1184,17 @@ var signInEmail = createAuthEndpoint(
1182
1184
  });
1183
1185
  }
1184
1186
  );
1187
+ var c = (o) => {
1188
+ };
1189
+ c({
1190
+ additional: {
1191
+ name: "string"
1192
+ },
1193
+ hooks: {
1194
+ create(user) {
1195
+ }
1196
+ }
1197
+ });
1185
1198
 
1186
1199
  // src/api/routes/callback.ts
1187
1200
  import { APIError as APIError4 } from "better-call";
@@ -1290,10 +1303,10 @@ function generateRandomInteger(max) {
1290
1303
  }
1291
1304
  return result;
1292
1305
  }
1293
- function generateRandomString(length, alphabet3) {
1306
+ function generateRandomString(length, alphabet4) {
1294
1307
  let result = "";
1295
1308
  for (let i = 0; i < length; i++) {
1296
- result += alphabet3[generateRandomInteger(alphabet3.length)];
1309
+ result += alphabet4[generateRandomInteger(alphabet4.length)];
1297
1310
  }
1298
1311
  return result;
1299
1312
  }
@@ -1352,63 +1365,63 @@ var callbackOAuth = createAuthEndpoint(
1352
1365
  }),
1353
1366
  metadata: HIDE_METADATA
1354
1367
  },
1355
- async (c) => {
1356
- if (c.query.error || !c.query.code) {
1357
- const parsedState2 = parseState(c.query.state);
1358
- const callbackURL2 = parsedState2.data?.callbackURL || `${c.context.baseURL}/error`;
1359
- c.context.logger.error(c.query.error, c.params.id);
1360
- throw c.redirect(
1361
- `${callbackURL2}?error=${c.query.error || "oAuth_code_missing"}`
1368
+ async (c2) => {
1369
+ if (c2.query.error || !c2.query.code) {
1370
+ const parsedState2 = parseState(c2.query.state);
1371
+ const callbackURL2 = parsedState2.data?.callbackURL || `${c2.context.baseURL}/error`;
1372
+ c2.context.logger.error(c2.query.error, c2.params.id);
1373
+ throw c2.redirect(
1374
+ `${callbackURL2}?error=${c2.query.error || "oAuth_code_missing"}`
1362
1375
  );
1363
1376
  }
1364
- const provider = c.context.socialProviders.find(
1365
- (p) => p.id === c.params.id
1377
+ const provider = c2.context.socialProviders.find(
1378
+ (p) => p.id === c2.params.id
1366
1379
  );
1367
1380
  if (!provider) {
1368
- c.context.logger.error(
1381
+ c2.context.logger.error(
1369
1382
  "Oauth provider with id",
1370
- c.params.id,
1383
+ c2.params.id,
1371
1384
  "not found"
1372
1385
  );
1373
- throw c.redirect(
1374
- `${c.context.baseURL}/error?error=oauth_provider_not_found`
1386
+ throw c2.redirect(
1387
+ `${c2.context.baseURL}/error?error=oauth_provider_not_found`
1375
1388
  );
1376
1389
  }
1377
- const parsedState = parseState(c.query.state);
1390
+ const parsedState = parseState(c2.query.state);
1378
1391
  if (!parsedState.success) {
1379
- c.context.logger.error("Unable to parse state");
1380
- throw c.redirect(
1381
- `${c.context.baseURL}/error?error=please_restart_the_process`
1392
+ c2.context.logger.error("Unable to parse state");
1393
+ throw c2.redirect(
1394
+ `${c2.context.baseURL}/error?error=please_restart_the_process`
1382
1395
  );
1383
1396
  }
1384
1397
  const {
1385
1398
  data: { callbackURL, currentURL, code: stateCode }
1386
1399
  } = parsedState;
1387
- const storedState = await c.getSignedCookie(
1388
- c.context.authCookies.state.name,
1389
- c.context.secret
1400
+ const storedState = await c2.getSignedCookie(
1401
+ c2.context.authCookies.state.name,
1402
+ c2.context.secret
1390
1403
  );
1391
1404
  if (storedState !== stateCode) {
1392
1405
  logger.error("OAuth state mismatch", storedState, stateCode);
1393
- throw c.redirect(
1394
- `${c.context.baseURL}/error?error=please_restart_the_process`
1406
+ throw c2.redirect(
1407
+ `${c2.context.baseURL}/error?error=please_restart_the_process`
1395
1408
  );
1396
1409
  }
1397
- const codeVerifier = await c.getSignedCookie(
1398
- c.context.authCookies.pkCodeVerifier.name,
1399
- c.context.secret
1410
+ const codeVerifier = await c2.getSignedCookie(
1411
+ c2.context.authCookies.pkCodeVerifier.name,
1412
+ c2.context.secret
1400
1413
  );
1401
1414
  let tokens;
1402
1415
  try {
1403
1416
  tokens = await provider.validateAuthorizationCode(
1404
- c.query.code,
1417
+ c2.query.code,
1405
1418
  codeVerifier,
1406
- `${c.context.baseURL}/callback/${provider.id}`
1419
+ `${c2.context.baseURL}/callback/${provider.id}`
1407
1420
  );
1408
1421
  } catch (e) {
1409
- c.context.logger.error(e);
1410
- throw c.redirect(
1411
- `${c.context.baseURL}/error?error=please_restart_the_process`
1422
+ c2.context.logger.error(e);
1423
+ throw c2.redirect(
1424
+ `${c2.context.baseURL}/error?error=please_restart_the_process`
1412
1425
  );
1413
1426
  }
1414
1427
  const user = await provider.getUserInfo(tokens).then((res) => res?.user);
@@ -1419,22 +1432,24 @@ var callbackOAuth = createAuthEndpoint(
1419
1432
  });
1420
1433
  if (!user || data.success === false) {
1421
1434
  logger.error("Unable to get user info", data.error);
1422
- throw c.redirect(
1423
- `${c.context.baseURL}/error?error=please_restart_the_process`
1435
+ throw c2.redirect(
1436
+ `${c2.context.baseURL}/error?error=please_restart_the_process`
1424
1437
  );
1425
1438
  }
1426
1439
  if (!callbackURL) {
1427
- throw c.redirect(
1428
- `${c.context.baseURL}/error?error=please_restart_the_process`
1440
+ throw c2.redirect(
1441
+ `${c2.context.baseURL}/error?error=please_restart_the_process`
1429
1442
  );
1430
1443
  }
1431
- const dbUser = await c.context.internalAdapter.findUserByEmail(user.email).catch((e) => {
1444
+ const dbUser = await c2.context.internalAdapter.findUserByEmail(user.email, {
1445
+ includeAccounts: true
1446
+ }).catch((e) => {
1432
1447
  logger.error(
1433
1448
  "Better auth was unable to query your database.\nError: ",
1434
1449
  e
1435
1450
  );
1436
- throw c.redirect(
1437
- `${c.context.baseURL}/error?error=internal_server_error`
1451
+ throw c2.redirect(
1452
+ `${c2.context.baseURL}/error?error=internal_server_error`
1438
1453
  );
1439
1454
  });
1440
1455
  const userId = dbUser?.user.id;
@@ -1442,7 +1457,7 @@ var callbackOAuth = createAuthEndpoint(
1442
1457
  const hasBeenLinked = dbUser.accounts.find(
1443
1458
  (a) => a.providerId === provider.id
1444
1459
  );
1445
- const trustedProviders = c.context.options.account?.accountLinking?.trustedProviders;
1460
+ const trustedProviders = c2.context.options.account?.accountLinking?.trustedProviders;
1446
1461
  const isTrustedProvider = trustedProviders ? trustedProviders.includes(provider.id) : true;
1447
1462
  if (!hasBeenLinked && (!user.emailVerified || !isTrustedProvider)) {
1448
1463
  let url;
@@ -1450,15 +1465,15 @@ var callbackOAuth = createAuthEndpoint(
1450
1465
  url = new URL(currentURL || callbackURL);
1451
1466
  url.searchParams.set("error", "account_not_linked");
1452
1467
  } catch (e) {
1453
- throw c.redirect(
1454
- `${c.context.baseURL}/error?error=account_not_linked`
1468
+ throw c2.redirect(
1469
+ `${c2.context.baseURL}/error?error=account_not_linked`
1455
1470
  );
1456
1471
  }
1457
- throw c.redirect(url.toString());
1472
+ throw c2.redirect(url.toString());
1458
1473
  }
1459
1474
  if (!hasBeenLinked) {
1460
1475
  try {
1461
- await c.context.internalAdapter.linkAccount({
1476
+ await c2.context.internalAdapter.linkAccount({
1462
1477
  providerId: provider.id,
1463
1478
  accountId: user.id.toString(),
1464
1479
  id: `${provider.id}:${user.id}`,
@@ -1467,14 +1482,14 @@ var callbackOAuth = createAuthEndpoint(
1467
1482
  });
1468
1483
  } catch (e) {
1469
1484
  console.log(e);
1470
- throw c.redirect(
1471
- `${c.context.baseURL}/error?error=failed_linking_account`
1485
+ throw c2.redirect(
1486
+ `${c2.context.baseURL}/error?error=failed_linking_account`
1472
1487
  );
1473
1488
  }
1474
1489
  }
1475
1490
  } else {
1476
1491
  try {
1477
- await c.context.internalAdapter.createOAuthUser(data.data, {
1492
+ await c2.context.internalAdapter.createOAuthUser(data.data, {
1478
1493
  ...getAccountTokens(tokens),
1479
1494
  id: `${provider.id}:${user.id}`,
1480
1495
  providerId: provider.id,
@@ -1484,8 +1499,8 @@ var callbackOAuth = createAuthEndpoint(
1484
1499
  } catch (e) {
1485
1500
  const url = new URL(currentURL || callbackURL);
1486
1501
  url.searchParams.set("error", "unable_to_create_user");
1487
- c.setHeader("Location", url.toString());
1488
- throw c.redirect(url.toString());
1502
+ c2.setHeader("Location", url.toString());
1503
+ throw c2.redirect(url.toString());
1489
1504
  }
1490
1505
  }
1491
1506
  if (!userId && !id)
@@ -1493,29 +1508,29 @@ var callbackOAuth = createAuthEndpoint(
1493
1508
  message: "Unable to create user"
1494
1509
  });
1495
1510
  try {
1496
- const session = await c.context.internalAdapter.createSession(
1511
+ const session = await c2.context.internalAdapter.createSession(
1497
1512
  userId || id,
1498
- c.request
1513
+ c2.request
1499
1514
  );
1500
1515
  if (!session) {
1501
1516
  const url = new URL(currentURL || callbackURL);
1502
1517
  url.searchParams.set("error", "unable_to_create_session");
1503
- throw c.redirect(url.toString());
1518
+ throw c2.redirect(url.toString());
1504
1519
  }
1505
1520
  try {
1506
- await setSessionCookie(c, session.id);
1521
+ await setSessionCookie(c2, session.id);
1507
1522
  } catch (e) {
1508
- c.context.logger.error("Unable to set session cookie", e);
1523
+ c2.context.logger.error("Unable to set session cookie", e);
1509
1524
  const url = new URL(currentURL || callbackURL);
1510
1525
  url.searchParams.set("error", "unable_to_create_session");
1511
- throw c.redirect(url.toString());
1526
+ throw c2.redirect(url.toString());
1512
1527
  }
1513
1528
  } catch {
1514
1529
  const url = new URL(currentURL || callbackURL || "");
1515
1530
  url.searchParams.set("error", "unable_to_create_session");
1516
- throw c.redirect(url.toString());
1531
+ throw c2.redirect(url.toString());
1517
1532
  }
1518
- throw c.redirect(callbackURL);
1533
+ throw c2.redirect(callbackURL);
1519
1534
  }
1520
1535
  );
1521
1536
 
@@ -1587,7 +1602,9 @@ var forgetPassword = createAuthEndpoint(
1587
1602
  });
1588
1603
  }
1589
1604
  const { email } = ctx.body;
1590
- const user = await ctx.context.internalAdapter.findUserByEmail(email);
1605
+ const user = await ctx.context.internalAdapter.findUserByEmail(email, {
1606
+ includeAccounts: true
1607
+ });
1591
1608
  if (!user) {
1592
1609
  ctx.context.logger.error("Reset Password: User not found", { email });
1593
1610
  return ctx.json(
@@ -1787,11 +1804,17 @@ var sendVerificationEmail = createAuthEndpoint(
1787
1804
  });
1788
1805
  }
1789
1806
  const { email } = ctx.body;
1807
+ const user = await ctx.context.internalAdapter.findUserByEmail(email);
1808
+ if (!user) {
1809
+ throw new APIError7("BAD_REQUEST", {
1810
+ message: "User not found"
1811
+ });
1812
+ }
1790
1813
  const token = await createEmailVerificationToken(ctx.context.secret, email);
1791
1814
  const url = `${ctx.context.baseURL}/verify-email?token=${token}&callbackURL=${ctx.body.callbackURL || ctx.query?.currentURL || "/"}`;
1792
1815
  await ctx.context.options.emailAndPassword.sendVerificationEmail(
1793
- email,
1794
1816
  url,
1817
+ user.user,
1795
1818
  token
1796
1819
  );
1797
1820
  return ctx.json({
@@ -1815,12 +1838,8 @@ var verifyEmail = createAuthEndpoint(
1815
1838
  jwt = await validateJWT2("HS256", Buffer.from(ctx.context.secret), token);
1816
1839
  } catch (e) {
1817
1840
  ctx.context.logger.error("Failed to verify email", e);
1818
- return ctx.json(null, {
1819
- status: 400,
1820
- statusText: "INVALID_TOKEN",
1821
- body: {
1822
- message: "Invalid token"
1823
- }
1841
+ throw new APIError7("BAD_REQUEST", {
1842
+ message: "Invalid token"
1824
1843
  });
1825
1844
  }
1826
1845
  const schema = z9.object({
@@ -1828,20 +1847,19 @@ var verifyEmail = createAuthEndpoint(
1828
1847
  });
1829
1848
  const parsed = schema.parse(jwt.payload);
1830
1849
  const user = await ctx.context.internalAdapter.findUserByEmail(
1831
- parsed.email
1850
+ parsed.email,
1851
+ { includeAccounts: true }
1832
1852
  );
1833
1853
  if (!user) {
1834
- return ctx.json(null, {
1835
- status: 400,
1836
- statusText: "USER_NOT_FOUND",
1837
- body: {
1838
- message: "User not found"
1839
- }
1854
+ throw new APIError7("BAD_REQUEST", {
1855
+ message: "User not found"
1840
1856
  });
1841
1857
  }
1842
1858
  const account = user.accounts.find((a) => a.providerId === "credential");
1843
1859
  if (!account) {
1844
- throw ctx.redirect;
1860
+ throw new APIError7("BAD_REQUEST", {
1861
+ message: "Account not found"
1862
+ });
1845
1863
  }
1846
1864
  await ctx.context.internalAdapter.updateUserByEmail(parsed.email, {
1847
1865
  emailVerified: true
@@ -2175,8 +2193,8 @@ var error = createAuthEndpoint(
2175
2193
  method: "GET",
2176
2194
  metadata: HIDE_METADATA
2177
2195
  },
2178
- async (c) => {
2179
- const query = new URL(c.request?.url || "").searchParams.get("error") || "Unknown";
2196
+ async (c2) => {
2197
+ const query = new URL(c2.request?.url || "").searchParams.get("error") || "Unknown";
2180
2198
  return new Response(html(query), {
2181
2199
  headers: {
2182
2200
  "Content-Type": "text/html"
@@ -2264,11 +2282,11 @@ var signUpEmail = () => createAuthEndpoint(
2264
2282
  }
2265
2283
  const hash = await ctx.context.password.hash(password);
2266
2284
  await ctx.context.internalAdapter.linkAccount({
2267
- id: generateRandomString(32, alphabet("a-z", "0-9", "A-Z")),
2268
2285
  userId: createdUser.id,
2269
2286
  providerId: "credential",
2270
2287
  accountId: createdUser.id,
2271
- password: hash
2288
+ password: hash,
2289
+ expiresAt: getDate(60 * 60 * 24 * 30, "sec")
2272
2290
  });
2273
2291
  const session = await ctx.context.internalAdapter.createSession(
2274
2292
  createdUser.id,
@@ -2287,8 +2305,8 @@ var signUpEmail = () => createAuthEndpoint(
2287
2305
  );
2288
2306
  const url = `${ctx.context.baseURL}/verify-email?token=${token}&callbackURL=${body.callbackURL || ctx.query?.currentURL || "/"}`;
2289
2307
  await ctx.context.options.emailAndPassword.sendVerificationEmail?.(
2290
- createdUser.email,
2291
2308
  url,
2309
+ createdUser,
2292
2310
  token
2293
2311
  );
2294
2312
  }
@@ -2569,26 +2587,26 @@ function getEndpoints(ctx, options) {
2569
2587
  let api = {};
2570
2588
  for (const [key, value] of Object.entries(endpoints)) {
2571
2589
  api[key] = async (context) => {
2572
- let c = await ctx;
2590
+ let c2 = await ctx;
2573
2591
  for (const plugin of options.plugins || []) {
2574
2592
  if (plugin.hooks?.before) {
2575
2593
  for (const hook of plugin.hooks.before) {
2576
2594
  const match = hook.matcher({
2577
2595
  ...value,
2578
2596
  ...context,
2579
- context: c
2597
+ context: c2
2580
2598
  });
2581
2599
  if (match) {
2582
2600
  const hookRes = await hook.handler({
2583
2601
  ...context,
2584
2602
  context: {
2585
- ...c,
2603
+ ...c2,
2586
2604
  ...context.context
2587
2605
  }
2588
2606
  });
2589
2607
  if (hookRes && "context" in hookRes) {
2590
- c = {
2591
- ...c,
2608
+ c2 = {
2609
+ ...c2,
2592
2610
  ...hookRes.context
2593
2611
  };
2594
2612
  }
@@ -2599,7 +2617,7 @@ function getEndpoints(ctx, options) {
2599
2617
  const endpointRes = await value({
2600
2618
  ...context,
2601
2619
  context: {
2602
- ...c,
2620
+ ...c2,
2603
2621
  ...context.context
2604
2622
  }
2605
2623
  });
package/dist/cli.js CHANGED
@@ -313,8 +313,6 @@ var getAuthTables = (options) => {
313
313
  }
314
314
  };
315
315
  const { user, session, account, ...pluginTables } = pluginSchema || {};
316
- const accountFields = options.account?.fields;
317
- const userFields = options.user?.fields;
318
316
  return {
319
317
  user: {
320
318
  tableName: options.user?.modelName || "user",
@@ -356,7 +354,7 @@ var getAuthTables = (options) => {
356
354
  ...user?.fields,
357
355
  ...options.user?.additionalFields
358
356
  },
359
- order: 0
357
+ order: 1
360
358
  },
361
359
  session: {
362
360
  tableName: options.session?.modelName || "session",
@@ -389,7 +387,7 @@ var getAuthTables = (options) => {
389
387
  ...session?.fields,
390
388
  ...options.session?.additionalFields
391
389
  },
392
- order: 1
390
+ order: 2
393
391
  },
394
392
  account: {
395
393
  tableName: options.account?.modelName || "account",
@@ -441,7 +439,7 @@ var getAuthTables = (options) => {
441
439
  },
442
440
  ...account?.fields
443
441
  },
444
- order: 2
442
+ order: 3
445
443
  },
446
444
  verification: {
447
445
  tableName: options.verification?.modelName || "verification",
@@ -461,7 +459,8 @@ var getAuthTables = (options) => {
461
459
  required: true,
462
460
  fieldName: options.verification?.fields?.expiresAt || "expiresAt"
463
461
  }
464
- }
462
+ },
463
+ order: 4
465
464
  },
466
465
  ...pluginTables,
467
466
  ...shouldAddRateLimitTable ? rateLimitTable : {}
@@ -2,10 +2,10 @@ 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, j as Organization, M as Member, I as Invitation, u as username, m as magicLink, d as phoneNumber, e as anonymous, i as admin } from '../index-CJ44EC0j.js';
6
- export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-CJ44EC0j.js';
5
+ import { o as organization, j as Organization, M as Member, I as Invitation, u as username, m as magicLink, d as phoneNumber, e as anonymous, i as admin } from '../index-DFhZxdCd.js';
6
+ export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-DFhZxdCd.js';
7
7
  import { P as Prettify } from '../helper-DPDj8Nix.js';
8
- import { F as FieldAttribute, B as BetterAuthOptions, b as BetterAuthPlugin } from '../index-Bt0CUdx4.js';
8
+ import { F as FieldAttribute, B as BetterAuthOptions, b as BetterAuthPlugin } from '../index-BJKlHmT9.js';
9
9
  import * as better_call from 'better-call';
10
10
  import { z } from 'zod';
11
11
  import { O as OAuth2Tokens, U as User } from '../types-IzAbV4nB.js';
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-Bt0CUdx4.js';
9
+ import './index-BJKlHmT9.js';
10
10
  import 'kysely';
11
11
  import './types-IzAbV4nB.js';
12
12
  import 'better-call';