better-auth 0.2.8-beta.2 → 0.2.8-beta.3

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-DAMIZ_6a.js';
1
+ import { A as Adapter } from '../index-CVYpdIik.js';
2
2
  import 'kysely';
3
3
  import '../index-XxjbEPqj.js';
4
4
  import 'arctic';
@@ -1,4 +1,4 @@
1
- import { W as Where } from '../index-DAMIZ_6a.js';
1
+ import { W as Where } from '../index-CVYpdIik.js';
2
2
  import 'kysely';
3
3
  import '../index-XxjbEPqj.js';
4
4
  import 'arctic';
@@ -1,4 +1,4 @@
1
- import { A as Adapter } from '../index-DAMIZ_6a.js';
1
+ import { A as Adapter } from '../index-CVYpdIik.js';
2
2
  import 'kysely';
3
3
  import '../index-XxjbEPqj.js';
4
4
  import 'arctic';
@@ -3,7 +3,7 @@ import path from 'path';
3
3
  import fs from 'fs/promises';
4
4
  import { produceSchema } from '@mrleebo/prisma-ast';
5
5
  import 'oslo';
6
- import 'oslo/crypto';
6
+ import 'nanoid';
7
7
  import { createConsola } from 'consola';
8
8
  import 'oslo/oauth2';
9
9
  import 'zod';
package/dist/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { b as AuthEndpoint, d as AuthMiddleware, y as callbackOAuth, X as changePassword, a as createAuthEndpoint, c as createAuthMiddleware, Q as createEmailVerificationToken, a1 as csrfMiddleware, _ as error, M as forgetPassword, N as forgetPasswordCallback, Z as getCSRFToken, u as getEndpoints, z as getSession, C as getSessionFromCtx, E as listSessions, $ as ok, o as optionsMiddleware, O as resetPassword, J as revokeSession, K as revokeSessions, v as router, T as sendVerificationEmail, D as sessionMiddleware, Y as setPassword, x as signInEmail, w as signInOAuth, L as signOut, a0 as signUpEmail, V as updateUser, U as verifyEmail } from './index-DAMIZ_6a.js';
1
+ export { b as AuthEndpoint, d as AuthMiddleware, y as callbackOAuth, X as changePassword, a as createAuthEndpoint, c as createAuthMiddleware, Q as createEmailVerificationToken, a1 as csrfMiddleware, _ as error, M as forgetPassword, N as forgetPasswordCallback, Z as getCSRFToken, u as getEndpoints, z as getSession, C as getSessionFromCtx, E as listSessions, $ as ok, o as optionsMiddleware, O as resetPassword, J as revokeSession, K as revokeSessions, v as router, T as sendVerificationEmail, D as sessionMiddleware, Y as setPassword, x as signInEmail, w as signInOAuth, L as signOut, a0 as signUpEmail, V as updateUser, U as verifyEmail } from './index-CVYpdIik.js';
2
2
  import 'zod';
3
3
  import './helper-D-PIAORk.js';
4
4
  import 'better-call';
package/dist/api.js CHANGED
@@ -10,6 +10,7 @@ import { createJWT, validateJWT, parseJWT } from 'oslo/jwt';
10
10
  import { betterFetch } from '@better-fetch/fetch';
11
11
  import { createConsola } from 'consola';
12
12
  import { TimeSpan } from 'oslo';
13
+ import { nanoid } from 'nanoid';
13
14
  import { generateRandomString, alphabet } from 'oslo/crypto';
14
15
  import chalk from 'chalk';
15
16
 
@@ -643,9 +644,9 @@ function parseState(state) {
643
644
  }
644
645
 
645
646
  // src/utils/date.ts
646
- var getDate = (span, isSeconds = false) => {
647
+ var getDate = (span, unit = "ms") => {
647
648
  const date = /* @__PURE__ */ new Date();
648
- return new Date(date.getTime() + (isSeconds ? span * 1e3 : span));
649
+ return new Date(date.getTime() + (unit === "sec" ? span * 1e3 : span));
649
650
  };
650
651
  async function setSessionCookie(ctx, sessionToken, dontRememberMe, overrides) {
651
652
  const options = ctx.context.authCookies.sessionToken.options;
@@ -702,7 +703,6 @@ function getIp(req) {
702
703
  }
703
704
 
704
705
  // src/api/routes/session.ts
705
- var sessionCache = /* @__PURE__ */ new Map();
706
706
  function getRequestUniqueKey(ctx, token) {
707
707
  if (!ctx.request) {
708
708
  return "";
@@ -732,15 +732,6 @@ var getSession = () => createAuthEndpoint(
732
732
  });
733
733
  }
734
734
  const key = getRequestUniqueKey(ctx, sessionCookieToken);
735
- const cachedSession = sessionCache.get(key);
736
- if (cachedSession) {
737
- if (cachedSession.expiresAt > Date.now()) {
738
- return ctx.json(
739
- cachedSession.data
740
- );
741
- }
742
- sessionCache.delete(key);
743
- }
744
735
  const session = await ctx.context.internalAdapter.findSession(sessionCookieToken);
745
736
  if (!session || session.session.expiresAt < /* @__PURE__ */ new Date()) {
746
737
  deleteSessionCookie(ctx);
@@ -768,7 +759,7 @@ var getSession = () => createAuthEndpoint(
768
759
  const updatedSession = await ctx.context.internalAdapter.updateSession(
769
760
  session.session.id,
770
761
  {
771
- expiresAt: getDate(ctx.context.sessionConfig.expiresIn, true)
762
+ expiresAt: getDate(ctx.context.sessionConfig.expiresIn, "sec")
772
763
  }
773
764
  );
774
765
  if (!updatedSession) {
@@ -784,10 +775,6 @@ var getSession = () => createAuthEndpoint(
784
775
  user: session.user
785
776
  });
786
777
  }
787
- sessionCache.set(key, {
788
- data: session,
789
- expiresAt: Date.now() + 5e3
790
- });
791
778
  return ctx.json(
792
779
  session
793
780
  );
@@ -1102,8 +1089,8 @@ z.object({
1102
1089
  expiresAt: z.date(),
1103
1090
  identifier: z.string()
1104
1091
  });
1105
- var generateId = () => {
1106
- return generateRandomString(36, alphabet("a-z", "0-9"));
1092
+ var generateId = (size) => {
1093
+ return nanoid(size);
1107
1094
  };
1108
1095
 
1109
1096
  // src/utils/hide-metadata.ts
package/dist/cli.js CHANGED
@@ -15,7 +15,7 @@ import prompts3 from 'prompts';
15
15
  import '@antfu/ni';
16
16
  import 'execa';
17
17
  import 'oslo';
18
- import 'oslo/crypto';
18
+ import 'nanoid';
19
19
  import 'oslo/oauth2';
20
20
  import fs from 'fs/promises';
21
21
 
@@ -339,39 +339,23 @@ var getAuthTables = (options) => {
339
339
  };
340
340
 
341
341
  // src/cli/utils/get-schema.ts
342
- function getPluginTable(config) {
343
- const pluginsMigrations = config.plugins?.flatMap(
344
- (plugin) => Object.keys(plugin.schema || {}).map((key) => {
345
- const schema = plugin.schema || {};
346
- const table = schema[key];
347
- if (table?.disableMigration) {
348
- return;
349
- }
350
- return {
351
- tableName: key,
352
- fields: table?.fields
353
- };
354
- }).filter((value) => value !== void 0)
355
- ) || [];
356
- return pluginsMigrations;
357
- }
358
342
  function getSchema(config) {
359
- const baseSchema = getAuthTables(config);
360
- const pluginSchema = getPluginTable(config);
361
- const schema = [
362
- baseSchema.user,
363
- baseSchema.session,
364
- baseSchema.account,
365
- ...pluginSchema
366
- ].reduce((acc, curr) => {
367
- acc[curr.tableName] = {
368
- fields: {
369
- ...acc[curr.tableName]?.fields,
370
- ...curr.fields
371
- }
343
+ const tables = getAuthTables(config);
344
+ let schema = {};
345
+ for (const key in tables) {
346
+ const table = tables[key];
347
+ if (schema[table.tableName]) {
348
+ schema[table.tableName].fields = {
349
+ ...schema[table.tableName].fields,
350
+ ...table.fields
351
+ };
352
+ continue;
353
+ }
354
+ schema[table.tableName] = {
355
+ fields: table.fields,
356
+ order: table.order || Infinity
372
357
  };
373
- return acc;
374
- }, {});
358
+ }
375
359
  return schema;
376
360
  }
377
361
 
@@ -2,14 +2,14 @@ import * as nanostores from 'nanostores';
2
2
  import { A as AccessControl, S as StatementsPrimitive, R as Role } from '../statement-BYDTZ_xW.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, d as Organization, M as Member, I as Invitation, u as username, m as magicLink } from '../index-C9Y_qmSM.js';
6
- export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-C9Y_qmSM.js';
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-CKRA1pd0.js';
6
+ export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-CKRA1pd0.js';
7
7
  import { P as Prettify } from '../helper-D-PIAORk.js';
8
8
  import '../index-XxjbEPqj.js';
9
9
  import 'arctic';
10
10
  import 'zod';
11
11
  import 'better-call';
12
- import '../index-DAMIZ_6a.js';
12
+ import '../index-CVYpdIik.js';
13
13
  import 'kysely';
14
14
  import 'better-sqlite3';
15
15
  import 'mysql2';
@@ -123,10 +123,13 @@ declare const organizationClient: <O extends OrganizationClientOptions>(options?
123
123
  isPending: boolean;
124
124
  }>;
125
125
  };
126
- atomListeners: {
126
+ atomListeners: ({
127
+ matcher(path: string): path is "/organization/create" | "/organization/delete";
128
+ signal: "_listOrg";
129
+ } | {
127
130
  matcher(path: string): boolean;
128
- signal: string;
129
- }[];
131
+ signal: "_activeOrgSignal";
132
+ })[];
130
133
  };
131
134
 
132
135
  declare const usernameClient: () => {
@@ -139,4 +142,13 @@ declare const magicLinkClient: () => {
139
142
  $InferServerPlugin: ReturnType<typeof magicLink>;
140
143
  };
141
144
 
142
- export { magicLinkClient, organizationClient, usernameClient };
145
+ declare const phoneNumberClient: () => {
146
+ id: "phoneNumber";
147
+ $InferServerPlugin: ReturnType<typeof phoneNumber>;
148
+ atomListeners: {
149
+ matcher(path: string): path is "/phone-number/verify" | "/phone-number/update";
150
+ signal: "_sessionSignal";
151
+ }[];
152
+ };
153
+
154
+ export { magicLinkClient, organizationClient, phoneNumberClient, usernameClient };
@@ -466,4 +466,20 @@ var magicLinkClient = () => {
466
466
  };
467
467
  };
468
468
 
469
- export { getPasskeyActions, magicLinkClient, organizationClient, passkeyClient, twoFactorClient, usernameClient };
469
+ // src/plugins/phone-number/client.ts
470
+ var phoneNumberClient = () => {
471
+ return {
472
+ id: "phoneNumber",
473
+ $InferServerPlugin: {},
474
+ atomListeners: [
475
+ {
476
+ matcher(path) {
477
+ return path === "/phone-number/update" || path === "/phone-number/verify";
478
+ },
479
+ signal: "_sessionSignal"
480
+ }
481
+ ]
482
+ };
483
+ };
484
+
485
+ export { getPasskeyActions, magicLinkClient, organizationClient, passkeyClient, phoneNumberClient, twoFactorClient, usernameClient };
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-D-PIAORk.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-DAMIZ_6a.js';
9
+ import './index-CVYpdIik.js';
10
10
  import 'kysely';
11
11
  import './index-XxjbEPqj.js';
12
12
  import 'arctic';