better-auth 0.2.4 → 0.2.5-beta.2

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.
@@ -0,0 +1,382 @@
1
+ // src/adapters/prisma-adapter/index.ts
2
+ import { existsSync } from "fs";
3
+ import path from "path";
4
+
5
+ // src/db/get-tables.ts
6
+ var getAuthTables = (options) => {
7
+ const pluginSchema = options.plugins?.reduce(
8
+ (acc, plugin) => {
9
+ const schema = plugin.schema;
10
+ if (!schema) return acc;
11
+ for (const [key, value] of Object.entries(schema)) {
12
+ acc[key] = {
13
+ fields: {
14
+ ...acc[key]?.fields,
15
+ ...value.fields
16
+ },
17
+ tableName: key
18
+ };
19
+ }
20
+ return acc;
21
+ },
22
+ {}
23
+ );
24
+ const shouldAddRateLimitTable = options.rateLimit?.storage === "database";
25
+ const rateLimitTable = {
26
+ rateLimit: {
27
+ tableName: options.rateLimit?.tableName || "rateLimit",
28
+ fields: {
29
+ key: {
30
+ type: "string"
31
+ },
32
+ count: {
33
+ type: "number"
34
+ },
35
+ lastRequest: {
36
+ type: "number"
37
+ }
38
+ }
39
+ }
40
+ };
41
+ const { user, session, account, ...pluginTables } = pluginSchema || {};
42
+ return {
43
+ user: {
44
+ tableName: options.user?.modelName || "user",
45
+ fields: {
46
+ name: {
47
+ type: "string",
48
+ required: true
49
+ },
50
+ email: {
51
+ type: "string",
52
+ unique: true,
53
+ required: true
54
+ },
55
+ emailVerified: {
56
+ type: "boolean",
57
+ defaultValue: () => false,
58
+ required: true
59
+ },
60
+ image: {
61
+ type: "string",
62
+ required: false
63
+ },
64
+ createdAt: {
65
+ type: "date",
66
+ defaultValue: () => /* @__PURE__ */ new Date(),
67
+ required: true
68
+ },
69
+ updatedAt: {
70
+ type: "date",
71
+ defaultValue: () => /* @__PURE__ */ new Date(),
72
+ required: true
73
+ },
74
+ ...user?.fields
75
+ },
76
+ order: 0
77
+ },
78
+ session: {
79
+ tableName: options.session?.modelName || "session",
80
+ fields: {
81
+ expiresAt: {
82
+ type: "date",
83
+ required: true
84
+ },
85
+ ipAddress: {
86
+ type: "string",
87
+ required: false
88
+ },
89
+ userAgent: {
90
+ type: "string",
91
+ required: false
92
+ },
93
+ userId: {
94
+ type: "string",
95
+ references: {
96
+ model: options.user?.modelName || "user",
97
+ field: "id",
98
+ onDelete: "cascade"
99
+ },
100
+ required: true
101
+ },
102
+ ...session?.fields
103
+ },
104
+ order: 1
105
+ },
106
+ account: {
107
+ tableName: options.account?.modelName || "account",
108
+ fields: {
109
+ accountId: {
110
+ type: "string",
111
+ required: true
112
+ },
113
+ providerId: {
114
+ type: "string",
115
+ required: true
116
+ },
117
+ userId: {
118
+ type: "string",
119
+ references: {
120
+ model: options.user?.modelName || "user",
121
+ field: "id",
122
+ onDelete: "cascade"
123
+ },
124
+ required: true
125
+ },
126
+ accessToken: {
127
+ type: "string",
128
+ required: false
129
+ },
130
+ refreshToken: {
131
+ type: "string",
132
+ required: false
133
+ },
134
+ idToken: {
135
+ type: "string",
136
+ required: false
137
+ },
138
+ expiresAt: {
139
+ type: "date",
140
+ required: false
141
+ },
142
+ password: {
143
+ type: "string",
144
+ required: false
145
+ },
146
+ ...account?.fields
147
+ },
148
+ order: 2
149
+ },
150
+ ...pluginTables,
151
+ ...shouldAddRateLimitTable ? rateLimitTable : {}
152
+ };
153
+ };
154
+
155
+ // src/adapters/prisma-adapter/index.ts
156
+ import fs from "fs/promises";
157
+ import { produceSchema } from "@mrleebo/prisma-ast";
158
+
159
+ // src/utils/cookies.ts
160
+ import { TimeSpan } from "oslo";
161
+
162
+ // src/utils/id.ts
163
+ import { alphabet, generateRandomString } from "oslo/crypto";
164
+
165
+ // src/utils/logger.ts
166
+ import { createConsola } from "consola";
167
+ var consola = createConsola({
168
+ formatOptions: {
169
+ date: false,
170
+ colors: true,
171
+ compact: true
172
+ },
173
+ defaults: {
174
+ tag: "Better Auth"
175
+ }
176
+ });
177
+ var createLogger = (options) => {
178
+ return {
179
+ log: (...args) => {
180
+ !options?.disabled && consola.log("", ...args);
181
+ },
182
+ error: (...args) => {
183
+ !options?.disabled && consola.error("", ...args);
184
+ },
185
+ warn: (...args) => {
186
+ !options?.disabled && consola.warn("", ...args);
187
+ },
188
+ info: (...args) => {
189
+ !options?.disabled && consola.info("", ...args);
190
+ },
191
+ debug: (...args) => {
192
+ !options?.disabled && consola.debug("", ...args);
193
+ },
194
+ box: (...args) => {
195
+ !options?.disabled && consola.box("", ...args);
196
+ },
197
+ success: (...args) => {
198
+ !options?.disabled && consola.success("", ...args);
199
+ },
200
+ break: (...args) => {
201
+ !options?.disabled && console.log("\n");
202
+ }
203
+ };
204
+ };
205
+ var logger = createLogger();
206
+
207
+ // src/utils/misc.ts
208
+ function capitalizeFirstLetter(str) {
209
+ return str.charAt(0).toUpperCase() + str.slice(1);
210
+ }
211
+
212
+ // src/utils/state.ts
213
+ import { generateState as generateStateOAuth } from "oslo/oauth2";
214
+ import { z } from "zod";
215
+
216
+ // src/adapters/prisma-adapter/index.ts
217
+ function whereConvertor(where) {
218
+ if (!where) return {};
219
+ if (where.length === 1) {
220
+ const w = where[0];
221
+ if (!w) {
222
+ return;
223
+ }
224
+ return {
225
+ [w.field]: w.value
226
+ };
227
+ }
228
+ const and = where.filter((w) => w.connector === "AND" || !w.connector);
229
+ const or = where.filter((w) => w.connector === "OR");
230
+ const andClause = and.map((w) => {
231
+ return {
232
+ [w.field]: w.operator === "eq" || !w.operator ? w.value : {
233
+ [w.operator]: w.value
234
+ }
235
+ };
236
+ });
237
+ const orClause = or.map((w) => {
238
+ return {
239
+ [w.field]: {
240
+ [w.operator || "eq"]: w.value
241
+ }
242
+ };
243
+ });
244
+ return {
245
+ AND: andClause.length ? andClause : void 0,
246
+ OR: orClause.length ? orClause : void 0
247
+ };
248
+ }
249
+ var prismaAdapter = (prisma, {
250
+ provider
251
+ }) => {
252
+ const db = prisma;
253
+ return {
254
+ id: "prisma",
255
+ async create(data) {
256
+ const { model, data: val, select } = data;
257
+ return await db[model].create({
258
+ data: val,
259
+ ...select?.length ? {
260
+ select: select.reduce((prev, cur) => {
261
+ return {
262
+ ...prev,
263
+ [cur]: true
264
+ };
265
+ }, {})
266
+ } : {}
267
+ });
268
+ },
269
+ async findOne(data) {
270
+ const { model, where, select } = data;
271
+ const whereClause = whereConvertor(where);
272
+ return await db[model].findFirst({
273
+ where: whereClause,
274
+ ...select?.length ? {
275
+ select: select.reduce((prev, cur) => {
276
+ return {
277
+ ...prev,
278
+ [cur]: true
279
+ };
280
+ }, {})
281
+ } : {}
282
+ });
283
+ },
284
+ async findMany(data) {
285
+ const { model, where } = data;
286
+ const whereClause = whereConvertor(where);
287
+ return await db[model].findMany({ where: whereClause });
288
+ },
289
+ async update(data) {
290
+ const { model, where, update } = data;
291
+ const whereClause = whereConvertor(where);
292
+ return await db[model].update({
293
+ where: whereClause,
294
+ data: update
295
+ });
296
+ },
297
+ async delete(data) {
298
+ const { model, where } = data;
299
+ const whereClause = whereConvertor(where);
300
+ return await db[model].delete({ where: whereClause });
301
+ },
302
+ async createSchema(options, file) {
303
+ const tables = getAuthTables(options);
304
+ const filePath = file || "./prisma/schema.prisma";
305
+ const schemaPrismaExist = existsSync(path.join(process.cwd(), filePath));
306
+ let schemaPrisma = "";
307
+ if (schemaPrismaExist) {
308
+ schemaPrisma = await fs.readFile(
309
+ path.join(process.cwd(), filePath),
310
+ "utf-8"
311
+ );
312
+ } else {
313
+ schemaPrisma = getNewPrisma(provider);
314
+ }
315
+ const schema = produceSchema(schemaPrisma, (builder) => {
316
+ for (const table in tables) {
317
+ let getType2 = function(type, isOptional) {
318
+ if (type === "string") {
319
+ return isOptional ? "String?" : "String";
320
+ }
321
+ if (type === "number") {
322
+ return isOptional ? "Int?" : "Int";
323
+ }
324
+ if (type === "boolean") {
325
+ return isOptional ? "Boolean?" : "Boolean";
326
+ }
327
+ if (type === "date") {
328
+ return isOptional ? "DateTime?" : "DateTime";
329
+ }
330
+ };
331
+ var getType = getType2;
332
+ const fields = tables[table].fields;
333
+ const tableName = tables[table].tableName;
334
+ const prismaModel = builder.findByType("model", {
335
+ name: tableName
336
+ });
337
+ !prismaModel && builder.model(tableName).field("id", "String").attribute("id");
338
+ for (const field in fields) {
339
+ const attr = fields[field];
340
+ if (prismaModel) {
341
+ const isAlreadyExist = builder.findByType("field", {
342
+ name: field,
343
+ within: prismaModel.properties
344
+ });
345
+ console.log(field, "exists");
346
+ if (isAlreadyExist) {
347
+ continue;
348
+ }
349
+ }
350
+ builder.model(tableName).field(field, getType2(attr.type, !attr.required));
351
+ if (attr.unique) {
352
+ builder.model(tableName).blockAttribute(`unique([${field}])`);
353
+ }
354
+ if (attr.references) {
355
+ builder.model(tableName).field(
356
+ capitalizeFirstLetter(attr.references.model),
357
+ attr.references.model
358
+ ).attribute(
359
+ `relation(fields: [${field}], references: [${attr.references.field}], onDelete: Cascade)`
360
+ );
361
+ }
362
+ }
363
+ }
364
+ });
365
+ return {
366
+ code: schema.trim() === schemaPrisma.trim() ? "" : schema,
367
+ fileName: filePath
368
+ };
369
+ }
370
+ };
371
+ };
372
+ var getNewPrisma = (provider) => `generator client {
373
+ provider = "prisma-client-js"
374
+ }
375
+
376
+ datasource db {
377
+ provider = "${provider}"
378
+ url = ${provider === "sqlite" ? `"file:./dev.db"` : `env("DATABASE_URL")`}
379
+ }`;
380
+ export {
381
+ prismaAdapter
382
+ };
package/dist/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AuthEndpoint, b 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-DH-qiFLO.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-CcdDoX76.js';
2
2
  import 'zod';
3
3
  import './helper-C1ihmerM.js';
4
4
  import 'better-call';
package/dist/cli.js CHANGED
@@ -359,7 +359,7 @@ var getAuthTables = (options) => {
359
359
  userId: {
360
360
  type: "string",
361
361
  references: {
362
- model: "user",
362
+ model: options.user?.modelName || "user",
363
363
  field: "id",
364
364
  onDelete: "cascade"
365
365
  },
@@ -383,7 +383,7 @@ var getAuthTables = (options) => {
383
383
  userId: {
384
384
  type: "string",
385
385
  references: {
386
- model: "user",
386
+ model: options.user?.modelName || "user",
387
387
  field: "id",
388
388
  onDelete: "cascade"
389
389
  },
@@ -2,14 +2,14 @@ import * as nanostores from 'nanostores';
2
2
  import { A as AccessControl, S as StatementsPrimitive, R as Role } from '../statement-CU-fdHXK.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-DeH0CN6S.js';
6
- export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-DeH0CN6S.js';
5
+ import { o as organization, d as Organization, M as Member, I as Invitation, u as username, m as magicLink } from '../index-D4lHPI1i.js';
6
+ export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-D4lHPI1i.js';
7
7
  import { P as Prettify } from '../helper-C1ihmerM.js';
8
8
  import '../index-CE92ti2Z.js';
9
9
  import 'arctic';
10
10
  import 'zod';
11
11
  import 'better-call';
12
- import '../index-DH-qiFLO.js';
12
+ import '../index-CcdDoX76.js';
13
13
  import 'kysely';
14
14
  import '@simplewebauthn/types';
15
15
 
package/dist/client.d.ts CHANGED
@@ -3,7 +3,7 @@ import * as nanostores from 'nanostores';
3
3
  import { PreinitializedWritableAtom } from 'nanostores';
4
4
  import * as _better_fetch_fetch from '@better-fetch/fetch';
5
5
  import { BetterFetch, BetterFetchError, BetterFetchOption } from '@better-fetch/fetch';
6
- import { B as BetterAuthPlugin, F as FieldAttribute, I as InferFieldOutput } from './index-DH-qiFLO.js';
6
+ import { B as BetterAuthPlugin, F as FieldAttribute, I as InferFieldOutput } from './index-CcdDoX76.js';
7
7
  import { U as UnionToIntersection, P as Prettify } from './helper-C1ihmerM.js';
8
8
  import { ClientOptions, InferClientAPI, InferActions, BetterAuthClientPlugin, InferSessionFromClient, InferUserFromClient, IsSignal } from './types.js';
9
9
  export { AtomListener, InferPluginsFromClient } from './types.js';
@@ -1291,17 +1291,17 @@ declare const signInOAuth: {
1291
1291
  /**
1292
1292
  * OAuth2 provider to use`
1293
1293
  */
1294
- provider: z.ZodEnum<["github", ...("github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter")[]]>;
1294
+ provider: z.ZodEnum<["github", ...("apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter")[]]>;
1295
1295
  /**
1296
1296
  * If this is true the session will only be valid for the current browser session
1297
1297
  */
1298
1298
  dontRememberMe: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
1299
1299
  }, "strip", z.ZodTypeAny, {
1300
- provider: "github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter";
1300
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter";
1301
1301
  callbackURL?: string | undefined;
1302
1302
  dontRememberMe?: boolean | undefined;
1303
1303
  }, {
1304
- provider: "github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter";
1304
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter";
1305
1305
  callbackURL?: string | undefined;
1306
1306
  dontRememberMe?: boolean | undefined;
1307
1307
  }>;
@@ -1334,17 +1334,17 @@ declare const signInOAuth: {
1334
1334
  /**
1335
1335
  * OAuth2 provider to use`
1336
1336
  */
1337
- provider: z.ZodEnum<["github", ...("github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter")[]]>;
1337
+ provider: z.ZodEnum<["github", ...("apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter")[]]>;
1338
1338
  /**
1339
1339
  * If this is true the session will only be valid for the current browser session
1340
1340
  */
1341
1341
  dontRememberMe: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
1342
1342
  }, "strip", z.ZodTypeAny, {
1343
- provider: "github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter";
1343
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter";
1344
1344
  callbackURL?: string | undefined;
1345
1345
  dontRememberMe?: boolean | undefined;
1346
1346
  }, {
1347
- provider: "github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter";
1347
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter";
1348
1348
  callbackURL?: string | undefined;
1349
1349
  dontRememberMe?: boolean | undefined;
1350
1350
  }>;
@@ -2428,14 +2428,14 @@ declare function getEndpoints<C extends AuthContext, Option extends BetterAuthOp
2428
2428
  }>>;
2429
2429
  body: zod.ZodObject<{
2430
2430
  callbackURL: zod.ZodOptional<zod.ZodString>;
2431
- provider: zod.ZodEnum<["github", ...("github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter")[]]>;
2431
+ provider: zod.ZodEnum<["github", ...("apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter")[]]>;
2432
2432
  dontRememberMe: zod.ZodOptional<zod.ZodDefault<zod.ZodBoolean>>;
2433
2433
  }, "strip", zod.ZodTypeAny, {
2434
- provider: "github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter";
2434
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter";
2435
2435
  callbackURL?: string | undefined;
2436
2436
  dontRememberMe?: boolean | undefined;
2437
2437
  }, {
2438
- provider: "github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter";
2438
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter";
2439
2439
  callbackURL?: string | undefined;
2440
2440
  dontRememberMe?: boolean | undefined;
2441
2441
  }>;
@@ -2458,14 +2458,14 @@ declare function getEndpoints<C extends AuthContext, Option extends BetterAuthOp
2458
2458
  }>>;
2459
2459
  body: zod.ZodObject<{
2460
2460
  callbackURL: zod.ZodOptional<zod.ZodString>;
2461
- provider: zod.ZodEnum<["github", ...("github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter")[]]>;
2461
+ provider: zod.ZodEnum<["github", ...("apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter")[]]>;
2462
2462
  dontRememberMe: zod.ZodOptional<zod.ZodDefault<zod.ZodBoolean>>;
2463
2463
  }, "strip", zod.ZodTypeAny, {
2464
- provider: "github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter";
2464
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter";
2465
2465
  callbackURL?: string | undefined;
2466
2466
  dontRememberMe?: boolean | undefined;
2467
2467
  }, {
2468
- provider: "github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter";
2468
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter";
2469
2469
  callbackURL?: string | undefined;
2470
2470
  dontRememberMe?: boolean | undefined;
2471
2471
  }>;
@@ -3425,14 +3425,14 @@ declare const router: <C extends AuthContext, Option extends BetterAuthOptions>(
3425
3425
  }>>;
3426
3426
  body: zod.ZodObject<{
3427
3427
  callbackURL: zod.ZodOptional<zod.ZodString>;
3428
- provider: zod.ZodEnum<["github", ...("github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter")[]]>;
3428
+ provider: zod.ZodEnum<["github", ...("apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter")[]]>;
3429
3429
  dontRememberMe: zod.ZodOptional<zod.ZodDefault<zod.ZodBoolean>>;
3430
3430
  }, "strip", zod.ZodTypeAny, {
3431
- provider: "github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter";
3431
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter";
3432
3432
  callbackURL?: string | undefined;
3433
3433
  dontRememberMe?: boolean | undefined;
3434
3434
  }, {
3435
- provider: "github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter";
3435
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter";
3436
3436
  callbackURL?: string | undefined;
3437
3437
  dontRememberMe?: boolean | undefined;
3438
3438
  }>;
@@ -3455,14 +3455,14 @@ declare const router: <C extends AuthContext, Option extends BetterAuthOptions>(
3455
3455
  }>>;
3456
3456
  body: zod.ZodObject<{
3457
3457
  callbackURL: zod.ZodOptional<zod.ZodString>;
3458
- provider: zod.ZodEnum<["github", ...("github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter")[]]>;
3458
+ provider: zod.ZodEnum<["github", ...("apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter")[]]>;
3459
3459
  dontRememberMe: zod.ZodOptional<zod.ZodDefault<zod.ZodBoolean>>;
3460
3460
  }, "strip", zod.ZodTypeAny, {
3461
- provider: "github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter";
3461
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter";
3462
3462
  callbackURL?: string | undefined;
3463
3463
  dontRememberMe?: boolean | undefined;
3464
3464
  }, {
3465
- provider: "github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter";
3465
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter";
3466
3466
  callbackURL?: string | undefined;
3467
3467
  dontRememberMe?: boolean | undefined;
3468
3468
  }>;
@@ -4424,14 +4424,14 @@ declare const betterAuth: <O extends BetterAuthOptions>(options: O) => {
4424
4424
  }>>;
4425
4425
  body: zod.ZodObject<{
4426
4426
  callbackURL: zod.ZodOptional<zod.ZodString>;
4427
- provider: zod.ZodEnum<["github", ...("github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter")[]]>;
4427
+ provider: zod.ZodEnum<["github", ...("apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter")[]]>;
4428
4428
  dontRememberMe: zod.ZodOptional<zod.ZodDefault<zod.ZodBoolean>>;
4429
4429
  }, "strip", zod.ZodTypeAny, {
4430
- provider: "github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter";
4430
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter";
4431
4431
  callbackURL?: string | undefined;
4432
4432
  dontRememberMe?: boolean | undefined;
4433
4433
  }, {
4434
- provider: "github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter";
4434
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter";
4435
4435
  callbackURL?: string | undefined;
4436
4436
  dontRememberMe?: boolean | undefined;
4437
4437
  }>;
@@ -4454,14 +4454,14 @@ declare const betterAuth: <O extends BetterAuthOptions>(options: O) => {
4454
4454
  }>>;
4455
4455
  body: zod.ZodObject<{
4456
4456
  callbackURL: zod.ZodOptional<zod.ZodString>;
4457
- provider: zod.ZodEnum<["github", ...("github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter")[]]>;
4457
+ provider: zod.ZodEnum<["github", ...("apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter")[]]>;
4458
4458
  dontRememberMe: zod.ZodOptional<zod.ZodDefault<zod.ZodBoolean>>;
4459
4459
  }, "strip", zod.ZodTypeAny, {
4460
- provider: "github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter";
4460
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter";
4461
4461
  callbackURL?: string | undefined;
4462
4462
  dontRememberMe?: boolean | undefined;
4463
4463
  }, {
4464
- provider: "github" | "apple" | "discord" | "facebook" | "google" | "spotify" | "twitch" | "twitter";
4464
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "spotify" | "twitch" | "twitter";
4465
4465
  callbackURL?: string | undefined;
4466
4466
  dontRememberMe?: boolean | undefined;
4467
4467
  }>;
@@ -5378,4 +5378,4 @@ type Auth = {
5378
5378
  options: BetterAuthOptions;
5379
5379
  };
5380
5380
 
5381
- export { ok as $, type AuthEndpoint as A, type BetterAuthPlugin as B, getSessionFromCtx as C, sessionMiddleware as D, listSessions as E, type FieldAttribute as F, type GenericEndpointContext as G, type HookEndpointContext as H, type InferFieldOutput as I, revokeSession as J, revokeSessions as K, signOut as L, forgetPassword as M, forgetPasswordCallback as N, resetPassword as O, type PluginSchema as P, createEmailVerificationToken as Q, type RateLimit as R, type SessionAdapter as S, sendVerificationEmail as T, verifyEmail as U, updateUser as V, type Where as W, changePassword as X, setPassword as Y, getCSRFToken as Z, error as _, createAuthEndpoint as a, signUpEmail as a0, csrfMiddleware as a1, betterAuth as a2, type AuthMiddleware as b, createAuthMiddleware as c, type Auth as d, type BetterAuthOptions as e, type Adapter as f, type AuthContext as g, getCookies as h, createCookieGetter as i, type BetterAuthCookies as j, deleteSessionCookie as k, createLogger as l, logger as m, type InferSession as n, optionsMiddleware as o, parseSetCookieHeader as p, type InferUser as q, type InferPluginTypes as r, setSessionCookie as s, init as t, getEndpoints as u, router as v, signInOAuth as w, signInEmail as x, callbackOAuth as y, getSession as z };
5381
+ export { ok as $, type Adapter as A, type BetterAuthPlugin as B, getSessionFromCtx as C, sessionMiddleware as D, listSessions as E, type FieldAttribute as F, type GenericEndpointContext as G, type HookEndpointContext as H, type InferFieldOutput as I, revokeSession as J, revokeSessions as K, signOut as L, forgetPassword as M, forgetPasswordCallback as N, resetPassword as O, type PluginSchema as P, createEmailVerificationToken as Q, type RateLimit as R, type SessionAdapter as S, sendVerificationEmail as T, verifyEmail as U, updateUser as V, type Where as W, changePassword as X, setPassword as Y, getCSRFToken as Z, error as _, createAuthEndpoint as a, signUpEmail as a0, csrfMiddleware as a1, betterAuth as a2, type AuthEndpoint as b, createAuthMiddleware as c, type AuthMiddleware as d, type Auth as e, type BetterAuthOptions as f, type AuthContext as g, getCookies as h, createCookieGetter as i, type BetterAuthCookies as j, deleteSessionCookie as k, createLogger as l, logger as m, type InferSession as n, optionsMiddleware as o, parseSetCookieHeader as p, type InferUser as q, type InferPluginTypes as r, setSessionCookie as s, init as t, getEndpoints as u, router as v, signInOAuth as w, signInEmail as x, callbackOAuth as y, getSession as z };
@@ -5,7 +5,7 @@ import { P as Prettify } from './helper-C1ihmerM.js';
5
5
  import { A as AccessControl, R as Role, S as StatementsPrimitive, g as defaultRoles } from './statement-CU-fdHXK.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-DH-qiFLO.js';
8
+ import { H as HookEndpointContext } from './index-CcdDoX76.js';
9
9
  import * as nanostores from 'nanostores';
10
10
  import { atom } from 'nanostores';
11
11
  import * as _simplewebauthn_types from '@simplewebauthn/types';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { d as Auth, a2 as betterAuth } from './index-DH-qiFLO.js';
1
+ export { e as Auth, a2 as betterAuth } from './index-CcdDoX76.js';
2
2
  import 'kysely';
3
3
  import './index-CE92ti2Z.js';
4
4
  import 'arctic';
package/dist/index.js CHANGED
@@ -2693,7 +2693,7 @@ var getAuthTables = (options) => {
2693
2693
  userId: {
2694
2694
  type: "string",
2695
2695
  references: {
2696
- model: "user",
2696
+ model: options.user?.modelName || "user",
2697
2697
  field: "id",
2698
2698
  onDelete: "cascade"
2699
2699
  },
@@ -2717,7 +2717,7 @@ var getAuthTables = (options) => {
2717
2717
  userId: {
2718
2718
  type: "string",
2719
2719
  references: {
2720
- model: "user",
2720
+ model: options.user?.modelName || "user",
2721
2721
  field: "id",
2722
2722
  onDelete: "cascade"
2723
2723
  },
package/dist/next-js.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { d as Auth } from './index-DH-qiFLO.js';
1
+ import { e as Auth } from './index-CcdDoX76.js';
2
2
  import { U as User, S as Session } from './index-CE92ti2Z.js';
3
3
  import { NextRequest } from 'next/server';
4
4
  import 'kysely';
@@ -16,7 +16,7 @@ declare function toNextJsHandler(auth: Auth | Auth["handler"]): {
16
16
  * If not, it redirects to the redirectTo URL.
17
17
  */
18
18
  declare function authMiddleware(options: {
19
- baePath?: string;
19
+ basePath?: string;
20
20
  redirectTo?: string;
21
21
  customRedirect?: (session: {
22
22
  user: User;
package/dist/next-js.js CHANGED
@@ -13,7 +13,7 @@ function toNextJsHandler(auth) {
13
13
  function authMiddleware(options) {
14
14
  return async (request) => {
15
15
  const url = new URL(request.url).origin;
16
- const basePath = options?.baePath || "/api/auth";
16
+ const basePath = options?.basePath || "/api/auth";
17
17
  const fullURL = `${url}${basePath}/session`;
18
18
  const res = await betterFetch(fullURL, {
19
19
  headers: request.headers