better-auth 0.4.4 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1146,39 +1146,39 @@ var signInOAuth = createAuthEndpoint(
1146
1146
  provider: z4.enum(oAuthProviderList)
1147
1147
  })
1148
1148
  },
1149
- async (c) => {
1150
- const provider = c.context.socialProviders.find(
1151
- (p) => p.id === c.body.provider
1149
+ async (c2) => {
1150
+ const provider = c2.context.socialProviders.find(
1151
+ (p) => p.id === c2.body.provider
1152
1152
  );
1153
1153
  if (!provider) {
1154
- c.context.logger.error(
1154
+ c2.context.logger.error(
1155
1155
  "Provider not found. Make sure to add the provider to your auth config",
1156
1156
  {
1157
- provider: c.body.provider
1157
+ provider: c2.body.provider
1158
1158
  }
1159
1159
  );
1160
1160
  throw new APIError3("NOT_FOUND", {
1161
1161
  message: "Provider not found"
1162
1162
  });
1163
1163
  }
1164
- const cookie = c.context.authCookies;
1165
- const currentURL = c.query?.currentURL ? new URL(c.query?.currentURL) : null;
1166
- const callbackURL = c.body.callbackURL?.startsWith("http") ? c.body.callbackURL : `${currentURL?.origin}${c.body.callbackURL || ""}`;
1164
+ const cookie = c2.context.authCookies;
1165
+ const currentURL = c2.query?.currentURL ? new URL(c2.query?.currentURL) : null;
1166
+ const callbackURL = c2.body.callbackURL?.startsWith("http") ? c2.body.callbackURL : `${currentURL?.origin}${c2.body.callbackURL || ""}`;
1167
1167
  const state = generateState(
1168
- callbackURL || currentURL?.origin || c.context.baseURL,
1169
- c.query?.currentURL
1168
+ callbackURL || currentURL?.origin || c2.context.baseURL,
1169
+ c2.query?.currentURL
1170
1170
  );
1171
- await c.setSignedCookie(
1171
+ await c2.setSignedCookie(
1172
1172
  cookie.state.name,
1173
1173
  state.code,
1174
- c.context.secret,
1174
+ c2.context.secret,
1175
1175
  cookie.state.options
1176
1176
  );
1177
1177
  const codeVerifier = generateCodeVerifier();
1178
- await c.setSignedCookie(
1178
+ await c2.setSignedCookie(
1179
1179
  cookie.pkCodeVerifier.name,
1180
1180
  codeVerifier,
1181
- c.context.secret,
1181
+ c2.context.secret,
1182
1182
  cookie.pkCodeVerifier.options
1183
1183
  );
1184
1184
  const url = await provider.createAuthorizationURL({
@@ -1187,9 +1187,9 @@ var signInOAuth = createAuthEndpoint(
1187
1187
  });
1188
1188
  url.searchParams.set(
1189
1189
  "redirect_uri",
1190
- `${c.context.baseURL}/callback/${c.body.provider}`
1190
+ `${c2.context.baseURL}/callback/${c2.body.provider}`
1191
1191
  );
1192
- return c.json({
1192
+ return c2.json({
1193
1193
  url: url.toString(),
1194
1194
  state: state.state,
1195
1195
  codeVerifier,
@@ -1234,7 +1234,9 @@ var signInEmail = createAuthEndpoint(
1234
1234
  message: "Invalid email"
1235
1235
  });
1236
1236
  }
1237
- const user = await ctx.context.internalAdapter.findUserByEmail(email);
1237
+ const user = await ctx.context.internalAdapter.findUserByEmail(email, {
1238
+ includeAccounts: true
1239
+ });
1238
1240
  if (!user) {
1239
1241
  await ctx.context.password.hash(password);
1240
1242
  ctx.context.logger.error("User not found", { email });
@@ -1288,6 +1290,17 @@ var signInEmail = createAuthEndpoint(
1288
1290
  });
1289
1291
  }
1290
1292
  );
1293
+ var c = (o) => {
1294
+ };
1295
+ c({
1296
+ additional: {
1297
+ name: "string"
1298
+ },
1299
+ hooks: {
1300
+ create(user) {
1301
+ }
1302
+ }
1303
+ });
1291
1304
 
1292
1305
  // src/api/routes/callback.ts
1293
1306
  import { APIError as APIError4 } from "better-call";
@@ -1396,10 +1409,10 @@ function generateRandomInteger(max) {
1396
1409
  }
1397
1410
  return result;
1398
1411
  }
1399
- function generateRandomString(length, alphabet3) {
1412
+ function generateRandomString(length, alphabet4) {
1400
1413
  let result = "";
1401
1414
  for (let i = 0; i < length; i++) {
1402
- result += alphabet3[generateRandomInteger(alphabet3.length)];
1415
+ result += alphabet4[generateRandomInteger(alphabet4.length)];
1403
1416
  }
1404
1417
  return result;
1405
1418
  }
@@ -1458,63 +1471,63 @@ var callbackOAuth = createAuthEndpoint(
1458
1471
  }),
1459
1472
  metadata: HIDE_METADATA
1460
1473
  },
1461
- async (c) => {
1462
- if (c.query.error || !c.query.code) {
1463
- const parsedState2 = parseState(c.query.state);
1464
- const callbackURL2 = parsedState2.data?.callbackURL || `${c.context.baseURL}/error`;
1465
- c.context.logger.error(c.query.error, c.params.id);
1466
- throw c.redirect(
1467
- `${callbackURL2}?error=${c.query.error || "oAuth_code_missing"}`
1474
+ async (c2) => {
1475
+ if (c2.query.error || !c2.query.code) {
1476
+ const parsedState2 = parseState(c2.query.state);
1477
+ const callbackURL2 = parsedState2.data?.callbackURL || `${c2.context.baseURL}/error`;
1478
+ c2.context.logger.error(c2.query.error, c2.params.id);
1479
+ throw c2.redirect(
1480
+ `${callbackURL2}?error=${c2.query.error || "oAuth_code_missing"}`
1468
1481
  );
1469
1482
  }
1470
- const provider = c.context.socialProviders.find(
1471
- (p) => p.id === c.params.id
1483
+ const provider = c2.context.socialProviders.find(
1484
+ (p) => p.id === c2.params.id
1472
1485
  );
1473
1486
  if (!provider) {
1474
- c.context.logger.error(
1487
+ c2.context.logger.error(
1475
1488
  "Oauth provider with id",
1476
- c.params.id,
1489
+ c2.params.id,
1477
1490
  "not found"
1478
1491
  );
1479
- throw c.redirect(
1480
- `${c.context.baseURL}/error?error=oauth_provider_not_found`
1492
+ throw c2.redirect(
1493
+ `${c2.context.baseURL}/error?error=oauth_provider_not_found`
1481
1494
  );
1482
1495
  }
1483
- const parsedState = parseState(c.query.state);
1496
+ const parsedState = parseState(c2.query.state);
1484
1497
  if (!parsedState.success) {
1485
- c.context.logger.error("Unable to parse state");
1486
- throw c.redirect(
1487
- `${c.context.baseURL}/error?error=please_restart_the_process`
1498
+ c2.context.logger.error("Unable to parse state");
1499
+ throw c2.redirect(
1500
+ `${c2.context.baseURL}/error?error=please_restart_the_process`
1488
1501
  );
1489
1502
  }
1490
1503
  const {
1491
1504
  data: { callbackURL, currentURL, code: stateCode }
1492
1505
  } = parsedState;
1493
- const storedState = await c.getSignedCookie(
1494
- c.context.authCookies.state.name,
1495
- c.context.secret
1506
+ const storedState = await c2.getSignedCookie(
1507
+ c2.context.authCookies.state.name,
1508
+ c2.context.secret
1496
1509
  );
1497
1510
  if (storedState !== stateCode) {
1498
1511
  logger.error("OAuth state mismatch", storedState, stateCode);
1499
- throw c.redirect(
1500
- `${c.context.baseURL}/error?error=please_restart_the_process`
1512
+ throw c2.redirect(
1513
+ `${c2.context.baseURL}/error?error=please_restart_the_process`
1501
1514
  );
1502
1515
  }
1503
- const codeVerifier = await c.getSignedCookie(
1504
- c.context.authCookies.pkCodeVerifier.name,
1505
- c.context.secret
1516
+ const codeVerifier = await c2.getSignedCookie(
1517
+ c2.context.authCookies.pkCodeVerifier.name,
1518
+ c2.context.secret
1506
1519
  );
1507
1520
  let tokens;
1508
1521
  try {
1509
1522
  tokens = await provider.validateAuthorizationCode(
1510
- c.query.code,
1523
+ c2.query.code,
1511
1524
  codeVerifier,
1512
- `${c.context.baseURL}/callback/${provider.id}`
1525
+ `${c2.context.baseURL}/callback/${provider.id}`
1513
1526
  );
1514
1527
  } catch (e) {
1515
- c.context.logger.error(e);
1516
- throw c.redirect(
1517
- `${c.context.baseURL}/error?error=please_restart_the_process`
1528
+ c2.context.logger.error(e);
1529
+ throw c2.redirect(
1530
+ `${c2.context.baseURL}/error?error=please_restart_the_process`
1518
1531
  );
1519
1532
  }
1520
1533
  const user = await provider.getUserInfo(tokens).then((res) => res?.user);
@@ -1525,22 +1538,24 @@ var callbackOAuth = createAuthEndpoint(
1525
1538
  });
1526
1539
  if (!user || data.success === false) {
1527
1540
  logger.error("Unable to get user info", data.error);
1528
- throw c.redirect(
1529
- `${c.context.baseURL}/error?error=please_restart_the_process`
1541
+ throw c2.redirect(
1542
+ `${c2.context.baseURL}/error?error=please_restart_the_process`
1530
1543
  );
1531
1544
  }
1532
1545
  if (!callbackURL) {
1533
- throw c.redirect(
1534
- `${c.context.baseURL}/error?error=please_restart_the_process`
1546
+ throw c2.redirect(
1547
+ `${c2.context.baseURL}/error?error=please_restart_the_process`
1535
1548
  );
1536
1549
  }
1537
- const dbUser = await c.context.internalAdapter.findUserByEmail(user.email).catch((e) => {
1550
+ const dbUser = await c2.context.internalAdapter.findUserByEmail(user.email, {
1551
+ includeAccounts: true
1552
+ }).catch((e) => {
1538
1553
  logger.error(
1539
1554
  "Better auth was unable to query your database.\nError: ",
1540
1555
  e
1541
1556
  );
1542
- throw c.redirect(
1543
- `${c.context.baseURL}/error?error=internal_server_error`
1557
+ throw c2.redirect(
1558
+ `${c2.context.baseURL}/error?error=internal_server_error`
1544
1559
  );
1545
1560
  });
1546
1561
  const userId = dbUser?.user.id;
@@ -1548,7 +1563,7 @@ var callbackOAuth = createAuthEndpoint(
1548
1563
  const hasBeenLinked = dbUser.accounts.find(
1549
1564
  (a) => a.providerId === provider.id
1550
1565
  );
1551
- const trustedProviders = c.context.options.account?.accountLinking?.trustedProviders;
1566
+ const trustedProviders = c2.context.options.account?.accountLinking?.trustedProviders;
1552
1567
  const isTrustedProvider = trustedProviders ? trustedProviders.includes(provider.id) : true;
1553
1568
  if (!hasBeenLinked && (!user.emailVerified || !isTrustedProvider)) {
1554
1569
  let url;
@@ -1556,15 +1571,15 @@ var callbackOAuth = createAuthEndpoint(
1556
1571
  url = new URL(currentURL || callbackURL);
1557
1572
  url.searchParams.set("error", "account_not_linked");
1558
1573
  } catch (e) {
1559
- throw c.redirect(
1560
- `${c.context.baseURL}/error?error=account_not_linked`
1574
+ throw c2.redirect(
1575
+ `${c2.context.baseURL}/error?error=account_not_linked`
1561
1576
  );
1562
1577
  }
1563
- throw c.redirect(url.toString());
1578
+ throw c2.redirect(url.toString());
1564
1579
  }
1565
1580
  if (!hasBeenLinked) {
1566
1581
  try {
1567
- await c.context.internalAdapter.linkAccount({
1582
+ await c2.context.internalAdapter.linkAccount({
1568
1583
  providerId: provider.id,
1569
1584
  accountId: user.id.toString(),
1570
1585
  id: `${provider.id}:${user.id}`,
@@ -1573,14 +1588,14 @@ var callbackOAuth = createAuthEndpoint(
1573
1588
  });
1574
1589
  } catch (e) {
1575
1590
  console.log(e);
1576
- throw c.redirect(
1577
- `${c.context.baseURL}/error?error=failed_linking_account`
1591
+ throw c2.redirect(
1592
+ `${c2.context.baseURL}/error?error=failed_linking_account`
1578
1593
  );
1579
1594
  }
1580
1595
  }
1581
1596
  } else {
1582
1597
  try {
1583
- await c.context.internalAdapter.createOAuthUser(data.data, {
1598
+ await c2.context.internalAdapter.createOAuthUser(data.data, {
1584
1599
  ...getAccountTokens(tokens),
1585
1600
  id: `${provider.id}:${user.id}`,
1586
1601
  providerId: provider.id,
@@ -1590,8 +1605,8 @@ var callbackOAuth = createAuthEndpoint(
1590
1605
  } catch (e) {
1591
1606
  const url = new URL(currentURL || callbackURL);
1592
1607
  url.searchParams.set("error", "unable_to_create_user");
1593
- c.setHeader("Location", url.toString());
1594
- throw c.redirect(url.toString());
1608
+ c2.setHeader("Location", url.toString());
1609
+ throw c2.redirect(url.toString());
1595
1610
  }
1596
1611
  }
1597
1612
  if (!userId && !id)
@@ -1599,29 +1614,29 @@ var callbackOAuth = createAuthEndpoint(
1599
1614
  message: "Unable to create user"
1600
1615
  });
1601
1616
  try {
1602
- const session = await c.context.internalAdapter.createSession(
1617
+ const session = await c2.context.internalAdapter.createSession(
1603
1618
  userId || id,
1604
- c.request
1619
+ c2.request
1605
1620
  );
1606
1621
  if (!session) {
1607
1622
  const url = new URL(currentURL || callbackURL);
1608
1623
  url.searchParams.set("error", "unable_to_create_session");
1609
- throw c.redirect(url.toString());
1624
+ throw c2.redirect(url.toString());
1610
1625
  }
1611
1626
  try {
1612
- await setSessionCookie(c, session.id);
1627
+ await setSessionCookie(c2, session.id);
1613
1628
  } catch (e) {
1614
- c.context.logger.error("Unable to set session cookie", e);
1629
+ c2.context.logger.error("Unable to set session cookie", e);
1615
1630
  const url = new URL(currentURL || callbackURL);
1616
1631
  url.searchParams.set("error", "unable_to_create_session");
1617
- throw c.redirect(url.toString());
1632
+ throw c2.redirect(url.toString());
1618
1633
  }
1619
1634
  } catch {
1620
1635
  const url = new URL(currentURL || callbackURL || "");
1621
1636
  url.searchParams.set("error", "unable_to_create_session");
1622
- throw c.redirect(url.toString());
1637
+ throw c2.redirect(url.toString());
1623
1638
  }
1624
- throw c.redirect(callbackURL);
1639
+ throw c2.redirect(callbackURL);
1625
1640
  }
1626
1641
  );
1627
1642
 
@@ -1693,7 +1708,9 @@ var forgetPassword = createAuthEndpoint(
1693
1708
  });
1694
1709
  }
1695
1710
  const { email } = ctx.body;
1696
- const user = await ctx.context.internalAdapter.findUserByEmail(email);
1711
+ const user = await ctx.context.internalAdapter.findUserByEmail(email, {
1712
+ includeAccounts: true
1713
+ });
1697
1714
  if (!user) {
1698
1715
  ctx.context.logger.error("Reset Password: User not found", { email });
1699
1716
  return ctx.json(
@@ -1893,11 +1910,17 @@ var sendVerificationEmail = createAuthEndpoint(
1893
1910
  });
1894
1911
  }
1895
1912
  const { email } = ctx.body;
1913
+ const user = await ctx.context.internalAdapter.findUserByEmail(email);
1914
+ if (!user) {
1915
+ throw new APIError7("BAD_REQUEST", {
1916
+ message: "User not found"
1917
+ });
1918
+ }
1896
1919
  const token = await createEmailVerificationToken(ctx.context.secret, email);
1897
1920
  const url = `${ctx.context.baseURL}/verify-email?token=${token}&callbackURL=${ctx.body.callbackURL || ctx.query?.currentURL || "/"}`;
1898
1921
  await ctx.context.options.emailAndPassword.sendVerificationEmail(
1899
- email,
1900
1922
  url,
1923
+ user.user,
1901
1924
  token
1902
1925
  );
1903
1926
  return ctx.json({
@@ -1921,12 +1944,8 @@ var verifyEmail = createAuthEndpoint(
1921
1944
  jwt = await validateJWT2("HS256", Buffer.from(ctx.context.secret), token);
1922
1945
  } catch (e) {
1923
1946
  ctx.context.logger.error("Failed to verify email", e);
1924
- return ctx.json(null, {
1925
- status: 400,
1926
- statusText: "INVALID_TOKEN",
1927
- body: {
1928
- message: "Invalid token"
1929
- }
1947
+ throw new APIError7("BAD_REQUEST", {
1948
+ message: "Invalid token"
1930
1949
  });
1931
1950
  }
1932
1951
  const schema = z9.object({
@@ -1934,20 +1953,19 @@ var verifyEmail = createAuthEndpoint(
1934
1953
  });
1935
1954
  const parsed = schema.parse(jwt.payload);
1936
1955
  const user = await ctx.context.internalAdapter.findUserByEmail(
1937
- parsed.email
1956
+ parsed.email,
1957
+ { includeAccounts: true }
1938
1958
  );
1939
1959
  if (!user) {
1940
- return ctx.json(null, {
1941
- status: 400,
1942
- statusText: "USER_NOT_FOUND",
1943
- body: {
1944
- message: "User not found"
1945
- }
1960
+ throw new APIError7("BAD_REQUEST", {
1961
+ message: "User not found"
1946
1962
  });
1947
1963
  }
1948
1964
  const account = user.accounts.find((a) => a.providerId === "credential");
1949
1965
  if (!account) {
1950
- throw ctx.redirect;
1966
+ throw new APIError7("BAD_REQUEST", {
1967
+ message: "Account not found"
1968
+ });
1951
1969
  }
1952
1970
  await ctx.context.internalAdapter.updateUserByEmail(parsed.email, {
1953
1971
  emailVerified: true
@@ -2281,8 +2299,8 @@ var error = createAuthEndpoint(
2281
2299
  method: "GET",
2282
2300
  metadata: HIDE_METADATA
2283
2301
  },
2284
- async (c) => {
2285
- const query = new URL(c.request?.url || "").searchParams.get("error") || "Unknown";
2302
+ async (c2) => {
2303
+ const query = new URL(c2.request?.url || "").searchParams.get("error") || "Unknown";
2286
2304
  return new Response(html(query), {
2287
2305
  headers: {
2288
2306
  "Content-Type": "text/html"
@@ -2370,11 +2388,11 @@ var signUpEmail = () => createAuthEndpoint(
2370
2388
  }
2371
2389
  const hash = await ctx.context.password.hash(password);
2372
2390
  await ctx.context.internalAdapter.linkAccount({
2373
- id: generateRandomString(32, alphabet("a-z", "0-9", "A-Z")),
2374
2391
  userId: createdUser.id,
2375
2392
  providerId: "credential",
2376
2393
  accountId: createdUser.id,
2377
- password: hash
2394
+ password: hash,
2395
+ expiresAt: getDate(60 * 60 * 24 * 30, "sec")
2378
2396
  });
2379
2397
  const session = await ctx.context.internalAdapter.createSession(
2380
2398
  createdUser.id,
@@ -2393,8 +2411,8 @@ var signUpEmail = () => createAuthEndpoint(
2393
2411
  );
2394
2412
  const url = `${ctx.context.baseURL}/verify-email?token=${token}&callbackURL=${body.callbackURL || ctx.query?.currentURL || "/"}`;
2395
2413
  await ctx.context.options.emailAndPassword.sendVerificationEmail?.(
2396
- createdUser.email,
2397
2414
  url,
2415
+ createdUser,
2398
2416
  token
2399
2417
  );
2400
2418
  }
@@ -2675,26 +2693,26 @@ function getEndpoints(ctx, options) {
2675
2693
  let api = {};
2676
2694
  for (const [key, value] of Object.entries(endpoints)) {
2677
2695
  api[key] = async (context) => {
2678
- let c = await ctx;
2696
+ let c2 = await ctx;
2679
2697
  for (const plugin of options.plugins || []) {
2680
2698
  if (plugin.hooks?.before) {
2681
2699
  for (const hook of plugin.hooks.before) {
2682
2700
  const match = hook.matcher({
2683
2701
  ...value,
2684
2702
  ...context,
2685
- context: c
2703
+ context: c2
2686
2704
  });
2687
2705
  if (match) {
2688
2706
  const hookRes = await hook.handler({
2689
2707
  ...context,
2690
2708
  context: {
2691
- ...c,
2709
+ ...c2,
2692
2710
  ...context.context
2693
2711
  }
2694
2712
  });
2695
2713
  if (hookRes && "context" in hookRes) {
2696
- c = {
2697
- ...c,
2714
+ c2 = {
2715
+ ...c2,
2698
2716
  ...hookRes.context
2699
2717
  };
2700
2718
  }
@@ -2705,7 +2723,7 @@ function getEndpoints(ctx, options) {
2705
2723
  const endpointRes = await value({
2706
2724
  ...context,
2707
2725
  context: {
2708
- ...c,
2726
+ ...c2,
2709
2727
  ...context.context
2710
2728
  }
2711
2729
  });
@@ -3224,7 +3242,7 @@ async function getMigrations(config2) {
3224
3242
  }
3225
3243
  let toBeAddedFields = {};
3226
3244
  for (const [fieldName, field] of Object.entries(value.fields)) {
3227
- const column = table.columns.find((c) => c.name === fieldName);
3245
+ const column = table.columns.find((c2) => c2.name === fieldName);
3228
3246
  if (!column) {
3229
3247
  toBeAddedFields[fieldName] = field;
3230
3248
  continue;
@@ -3551,11 +3569,11 @@ function constantTimeEqual(a, b) {
3551
3569
  if (aBuffer.length !== bBuffer.length) {
3552
3570
  return false;
3553
3571
  }
3554
- let c = 0;
3572
+ let c2 = 0;
3555
3573
  for (let i = 0; i < aBuffer.length; i++) {
3556
- c |= aBuffer[i] ^ bBuffer[i];
3574
+ c2 |= aBuffer[i] ^ bBuffer[i];
3557
3575
  }
3558
- return c === 0;
3576
+ return c2 === 0;
3559
3577
  }
3560
3578
 
3561
3579
  // src/crypto/password.ts
@@ -3747,12 +3765,11 @@ var createInternalAdapter = (adapter, ctx) => {
3747
3765
  ]
3748
3766
  });
3749
3767
  },
3750
- createSession: async (userId, request, dontRememberMe, inputData) => {
3768
+ createSession: async (userId, request, dontRememberMe, override) => {
3751
3769
  const headers = request instanceof Request ? request.headers : request;
3752
3770
  const data = {
3753
3771
  id: generateId(),
3754
3772
  userId,
3755
- ...inputData,
3756
3773
  /**
3757
3774
  * If the user doesn't want to be remembered
3758
3775
  * set the session to expire in 1 day.
@@ -3760,7 +3777,8 @@ var createInternalAdapter = (adapter, ctx) => {
3760
3777
  */
3761
3778
  expiresAt: dontRememberMe ? getDate(60 * 60 * 24, "sec") : getDate(sessionExpiration, "sec"),
3762
3779
  ipAddress: headers?.get("x-forwarded-for") || "",
3763
- userAgent: headers?.get("user-agent") || ""
3780
+ userAgent: headers?.get("user-agent") || "",
3781
+ ...override
3764
3782
  };
3765
3783
  const session = await createWithHooks(data, "session");
3766
3784
  if (secondaryStorage && session) {
@@ -3873,7 +3891,7 @@ var createInternalAdapter = (adapter, ctx) => {
3873
3891
  ]
3874
3892
  });
3875
3893
  },
3876
- findUserByEmail: async (email) => {
3894
+ findUserByEmail: async (email, options2) => {
3877
3895
  const user = await adapter.findOne({
3878
3896
  model: tables.user.tableName,
3879
3897
  where: [
@@ -3884,18 +3902,24 @@ var createInternalAdapter = (adapter, ctx) => {
3884
3902
  ]
3885
3903
  });
3886
3904
  if (!user) return null;
3887
- const accounts = await adapter.findMany({
3888
- model: tables.account.tableName,
3889
- where: [
3890
- {
3891
- value: user.id,
3892
- field: tables.account.fields.userId.fieldName || "userId"
3893
- }
3894
- ]
3895
- });
3905
+ if (options2?.includeAccounts) {
3906
+ const accounts = await adapter.findMany({
3907
+ model: tables.account.tableName,
3908
+ where: [
3909
+ {
3910
+ value: user.id,
3911
+ field: tables.account.fields.userId.fieldName || "userId"
3912
+ }
3913
+ ]
3914
+ });
3915
+ return {
3916
+ user,
3917
+ accounts
3918
+ };
3919
+ }
3896
3920
  return {
3897
3921
  user,
3898
- accounts
3922
+ accounts: []
3899
3923
  };
3900
3924
  },
3901
3925
  findUserById: async (userId) => {
@@ -3913,6 +3937,7 @@ var createInternalAdapter = (adapter, ctx) => {
3913
3937
  linkAccount: async (account) => {
3914
3938
  const _account = await createWithHooks(
3915
3939
  {
3940
+ id: generateId(),
3916
3941
  ...account
3917
3942
  },
3918
3943
  "account"
@@ -4109,7 +4134,7 @@ function runPluginInit(ctx) {
4109
4134
  let options = ctx.options;
4110
4135
  const plugins = options.plugins || [];
4111
4136
  let context = ctx;
4112
- const dbHooks = [options.databaseHooks];
4137
+ const dbHooks = [];
4113
4138
  for (const plugin of plugins) {
4114
4139
  if (plugin.init) {
4115
4140
  const result = plugin.init(ctx);
@@ -4129,6 +4154,7 @@ function runPluginInit(ctx) {
4129
4154
  }
4130
4155
  }
4131
4156
  }
4157
+ dbHooks.push(options.databaseHooks);
4132
4158
  context.internalAdapter = createInternalAdapter(ctx.adapter, {
4133
4159
  options,
4134
4160
  hooks: dbHooks.filter((u) => u !== void 0)
package/dist/next-js.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as Auth } from './index-Bt0CUdx4.js';
1
+ import { a as Auth } from './index-B5SM-JCa.js';
2
2
  import { U as User, S as Session } from './types-IzAbV4nB.js';
3
3
  import { NextRequest } from 'next/server';
4
4
  import 'zod';
package/dist/node.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as http from 'http';
2
- import { a as Auth } from './index-Bt0CUdx4.js';
2
+ import { a as Auth } from './index-B5SM-JCa.js';
3
3
  import 'zod';
4
4
  import 'kysely';
5
5
  import './types-IzAbV4nB.js';
package/dist/plugins.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { A as AnonymousOptions, O as OrganizationOptions, b as Passkey, P as PasskeyOptions, U as UserWithPhoneNumber, f as UserWithRole, i as admin, h as adminMiddleware, 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-CJ44EC0j.js';
1
+ export { A as AnonymousOptions, O as OrganizationOptions, b as Passkey, P as PasskeyOptions, U as UserWithPhoneNumber, f as UserWithRole, i as admin, h as adminMiddleware, 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-45sX2yHG.js';
2
2
  export { i as ac } from './index-DfAHOgpj.js';
3
- import { H as HookEndpointContext } from './index-Bt0CUdx4.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-Bt0CUdx4.js';
3
+ import { H as HookEndpointContext } from './index-B5SM-JCa.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-B5SM-JCa.js';
5
5
  import './types-IzAbV4nB.js';
6
6
  import 'zod';
7
7
  import './helper-DPDj8Nix.js';