better-auth 0.2.8-beta.1 → 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,6 +1,6 @@
1
- import { A as Adapter } from '../index-BC-04Tu0.js';
1
+ import { A as Adapter } from '../index-CVYpdIik.js';
2
2
  import 'kysely';
3
- import '../index-37csVPVw.js';
3
+ import '../index-XxjbEPqj.js';
4
4
  import 'arctic';
5
5
  import 'zod';
6
6
  import '../helper-D-PIAORk.js';
@@ -41,11 +41,13 @@ 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;
44
46
  return {
45
47
  user: {
46
48
  tableName: options.user?.modelName || "user",
47
49
  fields: {
48
- name: {
50
+ [userFields?.name || "name"]: {
49
51
  type: "string",
50
52
  required: true
51
53
  },
@@ -108,7 +110,7 @@ var getAuthTables = (options) => {
108
110
  account: {
109
111
  tableName: options.account?.modelName || "account",
110
112
  fields: {
111
- accountId: {
113
+ [accountFields?.accountId || "accountId"]: {
112
114
  type: "string",
113
115
  required: true
114
116
  },
@@ -149,6 +151,23 @@ var getAuthTables = (options) => {
149
151
  },
150
152
  order: 2
151
153
  },
154
+ verification: {
155
+ tableName: options.verification?.modelName || "verification",
156
+ fields: {
157
+ identifier: {
158
+ type: "string",
159
+ required: true
160
+ },
161
+ value: {
162
+ type: "string",
163
+ required: true
164
+ },
165
+ expiresAt: {
166
+ type: "date",
167
+ required: true
168
+ }
169
+ }
170
+ },
152
171
  ...pluginTables,
153
172
  ...shouldAddRateLimitTable ? rateLimitTable : {}
154
173
  };
@@ -1,6 +1,6 @@
1
- import { W as Where } from '../index-BC-04Tu0.js';
1
+ import { W as Where } from '../index-CVYpdIik.js';
2
2
  import 'kysely';
3
- import '../index-37csVPVw.js';
3
+ import '../index-XxjbEPqj.js';
4
4
  import 'arctic';
5
5
  import 'zod';
6
6
  import '../helper-D-PIAORk.js';
@@ -1,6 +1,6 @@
1
- import { A as Adapter } from '../index-BC-04Tu0.js';
1
+ import { A as Adapter } from '../index-CVYpdIik.js';
2
2
  import 'kysely';
3
- import '../index-37csVPVw.js';
3
+ import '../index-XxjbEPqj.js';
4
4
  import 'arctic';
5
5
  import 'zod';
6
6
  import '../helper-D-PIAORk.js';
@@ -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';
@@ -47,11 +47,13 @@ var getAuthTables = (options) => {
47
47
  }
48
48
  };
49
49
  const { user, session, account, ...pluginTables } = pluginSchema || {};
50
+ const accountFields = options.account?.fields;
51
+ const userFields = options.user?.fields;
50
52
  return {
51
53
  user: {
52
54
  tableName: options.user?.modelName || "user",
53
55
  fields: {
54
- name: {
56
+ [userFields?.name || "name"]: {
55
57
  type: "string",
56
58
  required: true
57
59
  },
@@ -114,7 +116,7 @@ var getAuthTables = (options) => {
114
116
  account: {
115
117
  tableName: options.account?.modelName || "account",
116
118
  fields: {
117
- accountId: {
119
+ [accountFields?.accountId || "accountId"]: {
118
120
  type: "string",
119
121
  required: true
120
122
  },
@@ -155,6 +157,23 @@ var getAuthTables = (options) => {
155
157
  },
156
158
  order: 2
157
159
  },
160
+ verification: {
161
+ tableName: options.verification?.modelName || "verification",
162
+ fields: {
163
+ identifier: {
164
+ type: "string",
165
+ required: true
166
+ },
167
+ value: {
168
+ type: "string",
169
+ required: true
170
+ },
171
+ expiresAt: {
172
+ type: "date",
173
+ required: true
174
+ }
175
+ }
176
+ },
158
177
  ...pluginTables,
159
178
  ...shouldAddRateLimitTable ? rateLimitTable : {}
160
179
  };
package/dist/api.d.ts CHANGED
@@ -1,9 +1,9 @@
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-BC-04Tu0.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';
5
5
  import 'kysely';
6
- import './index-37csVPVw.js';
6
+ import './index-XxjbEPqj.js';
7
7
  import 'arctic';
8
8
  import 'better-sqlite3';
9
9
  import 'mysql2';
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
  );
@@ -1096,8 +1083,14 @@ z.object({
1096
1083
  ipAddress: z.string().optional(),
1097
1084
  userAgent: z.string().optional()
1098
1085
  });
1099
- var generateId = () => {
1100
- return generateRandomString(36, alphabet("a-z", "0-9"));
1086
+ z.object({
1087
+ id: z.string(),
1088
+ value: z.string(),
1089
+ expiresAt: z.date(),
1090
+ identifier: z.string()
1091
+ });
1092
+ var generateId = (size) => {
1093
+ return nanoid(size);
1101
1094
  };
1102
1095
 
1103
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
 
@@ -206,11 +206,13 @@ var getAuthTables = (options) => {
206
206
  }
207
207
  };
208
208
  const { user, session, account, ...pluginTables } = pluginSchema || {};
209
+ const accountFields = options.account?.fields;
210
+ const userFields = options.user?.fields;
209
211
  return {
210
212
  user: {
211
213
  tableName: options.user?.modelName || "user",
212
214
  fields: {
213
- name: {
215
+ [userFields?.name || "name"]: {
214
216
  type: "string",
215
217
  required: true
216
218
  },
@@ -273,7 +275,7 @@ var getAuthTables = (options) => {
273
275
  account: {
274
276
  tableName: options.account?.modelName || "account",
275
277
  fields: {
276
- accountId: {
278
+ [accountFields?.accountId || "accountId"]: {
277
279
  type: "string",
278
280
  required: true
279
281
  },
@@ -314,45 +316,46 @@ var getAuthTables = (options) => {
314
316
  },
315
317
  order: 2
316
318
  },
319
+ verification: {
320
+ tableName: options.verification?.modelName || "verification",
321
+ fields: {
322
+ identifier: {
323
+ type: "string",
324
+ required: true
325
+ },
326
+ value: {
327
+ type: "string",
328
+ required: true
329
+ },
330
+ expiresAt: {
331
+ type: "date",
332
+ required: true
333
+ }
334
+ }
335
+ },
317
336
  ...pluginTables,
318
337
  ...shouldAddRateLimitTable ? rateLimitTable : {}
319
338
  };
320
339
  };
321
340
 
322
341
  // src/cli/utils/get-schema.ts
323
- function getPluginTable(config) {
324
- const pluginsMigrations = config.plugins?.flatMap(
325
- (plugin) => Object.keys(plugin.schema || {}).map((key) => {
326
- const schema = plugin.schema || {};
327
- const table = schema[key];
328
- if (table?.disableMigration) {
329
- return;
330
- }
331
- return {
332
- tableName: key,
333
- fields: table?.fields
334
- };
335
- }).filter((value) => value !== void 0)
336
- ) || [];
337
- return pluginsMigrations;
338
- }
339
342
  function getSchema(config) {
340
- const baseSchema = getAuthTables(config);
341
- const pluginSchema = getPluginTable(config);
342
- const schema = [
343
- baseSchema.user,
344
- baseSchema.session,
345
- baseSchema.account,
346
- ...pluginSchema
347
- ].reduce((acc, curr) => {
348
- acc[curr.tableName] = {
349
- fields: {
350
- ...acc[curr.tableName]?.fields,
351
- ...curr.fields
352
- }
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
353
357
  };
354
- return acc;
355
- }, {});
358
+ }
356
359
  return schema;
357
360
  }
358
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-DKbdF1U-.js';
6
- export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-DKbdF1U-.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
- import '../index-37csVPVw.js';
8
+ import '../index-XxjbEPqj.js';
9
9
  import 'arctic';
10
10
  import 'zod';
11
11
  import 'better-call';
12
- import '../index-BC-04Tu0.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,9 +6,9 @@ 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-BC-04Tu0.js';
9
+ import './index-CVYpdIik.js';
10
10
  import 'kysely';
11
- import './index-37csVPVw.js';
11
+ import './index-XxjbEPqj.js';
12
12
  import 'arctic';
13
13
  import 'better-call';
14
14
  import 'better-sqlite3';