better-auth 0.2.6 → 0.2.8-beta.10
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/.DS_Store +0 -0
- package/dist/access.d.ts +3 -3
- package/dist/adapters/drizzle.d.ts +9 -3
- package/dist/adapters/drizzle.js +70 -13
- package/dist/adapters/mongodb.d.ts +3 -3
- package/dist/adapters/prisma.d.ts +3 -3
- package/dist/adapters/prisma.js +22 -3
- package/dist/api.d.ts +3 -3
- package/dist/api.js +247 -158
- package/dist/cli.js +42 -41
- package/dist/client/plugins.d.ts +22 -10
- package/dist/client/plugins.js +32 -12
- package/dist/client.d.ts +3 -3
- package/dist/client.js +21 -6
- package/dist/{helper-D-PIAORk.d.ts → helper-DPDj8Nix.d.ts} +4 -1
- package/dist/{index-Cc76Cf2k.d.ts → index-C1aItpHl.d.ts} +603 -268
- package/dist/{index-Ckd9h_O2.d.ts → index-DFyIXQyt.d.ts} +569 -335
- package/dist/{index-D1yWsqP4.d.ts → index-DfAHOgpj.d.ts} +1 -1
- package/dist/{index-37csVPVw.d.ts → index-JM-i6hLs.d.ts} +19 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +604 -428
- package/dist/next-js.d.ts +4 -4
- package/dist/node.d.ts +3 -3
- package/dist/plugins.d.ts +7 -7
- package/dist/plugins.js +709 -215
- package/dist/react.d.ts +3 -3
- package/dist/react.js +21 -6
- package/dist/social.d.ts +2 -2
- package/dist/social.js +54 -52
- package/dist/solid-start.d.ts +3 -3
- package/dist/solid.d.ts +3 -3
- package/dist/solid.js +21 -6
- package/dist/{statement-BYDTZ_xW.d.ts → statement-CfnyN34h.d.ts} +1 -1
- package/dist/svelte-kit.d.ts +3 -3
- package/dist/svelte.d.ts +3 -3
- package/dist/svelte.js +21 -6
- package/dist/types.d.ts +25 -12
- package/dist/utils.d.ts +8 -8
- package/dist/utils.js +8 -8
- package/dist/vue.d.ts +3 -3
- package/dist/vue.js +21 -6
- package/package.json +2 -1
package/dist/.DS_Store
ADDED
|
Binary file
|
package/dist/access.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AccessControl, a as AuthortizeResponse, P as ParsingError, R as Role, S as StatementsPrimitive, b as SubArray, c as Subset, d as adminAc, e as createAccessControl, f as defaultAc, g as defaultRoles, h as defaultStatements, m as memberAc, o as ownerAc } from './statement-
|
|
2
|
-
export { p as permissionFromString } from './index-
|
|
3
|
-
import './helper-
|
|
1
|
+
export { A as AccessControl, a as AuthortizeResponse, P as ParsingError, R as Role, S as StatementsPrimitive, b as SubArray, c as Subset, d as adminAc, e as createAccessControl, f as defaultAc, g as defaultRoles, h as defaultStatements, m as memberAc, o as ownerAc } from './statement-CfnyN34h.js';
|
|
2
|
+
export { p as permissionFromString } from './index-DfAHOgpj.js';
|
|
3
|
+
import './helper-DPDj8Nix.js';
|
|
4
4
|
import 'zod';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { A as Adapter } from '../index-
|
|
1
|
+
import { A as Adapter } from '../index-DFyIXQyt.js';
|
|
2
2
|
import 'kysely';
|
|
3
|
-
import '../index-
|
|
3
|
+
import '../index-JM-i6hLs.js';
|
|
4
4
|
import 'arctic';
|
|
5
5
|
import 'zod';
|
|
6
|
-
import '../helper-
|
|
6
|
+
import '../helper-DPDj8Nix.js';
|
|
7
7
|
import 'better-call';
|
|
8
8
|
import 'better-sqlite3';
|
|
9
9
|
import 'mysql2';
|
|
@@ -11,6 +11,12 @@ import 'mysql2';
|
|
|
11
11
|
interface DrizzleAdapterOptions {
|
|
12
12
|
schema?: Record<string, any>;
|
|
13
13
|
provider: "pg" | "mysql" | "sqlite";
|
|
14
|
+
/**
|
|
15
|
+
* If the table names in the schema are plural
|
|
16
|
+
* set this to true. For example, if the schema
|
|
17
|
+
* has an object with a key "users" instead of "user"
|
|
18
|
+
*/
|
|
19
|
+
usePlural?: boolean;
|
|
14
20
|
}
|
|
15
21
|
interface DB {
|
|
16
22
|
[key: string]: any;
|
package/dist/adapters/drizzle.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { eq, and, or } from 'drizzle-orm';
|
|
2
2
|
import { existsSync } from 'fs';
|
|
3
3
|
import fs from 'fs/promises';
|
|
4
|
+
import 'oslo';
|
|
5
|
+
import 'nanoid';
|
|
6
|
+
import { createConsola } from 'consola';
|
|
7
|
+
import 'oslo/oauth2';
|
|
8
|
+
import 'zod';
|
|
9
|
+
import 'chalk';
|
|
4
10
|
|
|
5
11
|
// src/adapters/drizzle-adapter/index.ts
|
|
6
12
|
|
|
@@ -41,11 +47,13 @@ var getAuthTables = (options) => {
|
|
|
41
47
|
}
|
|
42
48
|
};
|
|
43
49
|
const { user, session, account, ...pluginTables } = pluginSchema || {};
|
|
50
|
+
const accountFields = options.account?.fields;
|
|
51
|
+
const userFields = options.user?.fields;
|
|
44
52
|
return {
|
|
45
53
|
user: {
|
|
46
54
|
tableName: options.user?.modelName || "user",
|
|
47
55
|
fields: {
|
|
48
|
-
name: {
|
|
56
|
+
[userFields?.name || "name"]: {
|
|
49
57
|
type: "string",
|
|
50
58
|
required: true
|
|
51
59
|
},
|
|
@@ -108,7 +116,7 @@ var getAuthTables = (options) => {
|
|
|
108
116
|
account: {
|
|
109
117
|
tableName: options.account?.modelName || "account",
|
|
110
118
|
fields: {
|
|
111
|
-
accountId: {
|
|
119
|
+
[accountFields?.accountId || "accountId"]: {
|
|
112
120
|
type: "string",
|
|
113
121
|
required: true
|
|
114
122
|
},
|
|
@@ -149,14 +157,41 @@ var getAuthTables = (options) => {
|
|
|
149
157
|
},
|
|
150
158
|
order: 2
|
|
151
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
|
+
},
|
|
152
177
|
...pluginTables,
|
|
153
178
|
...shouldAddRateLimitTable ? rateLimitTable : {}
|
|
154
179
|
};
|
|
155
180
|
};
|
|
181
|
+
createConsola({
|
|
182
|
+
formatOptions: {
|
|
183
|
+
date: false,
|
|
184
|
+
colors: true,
|
|
185
|
+
compact: true
|
|
186
|
+
},
|
|
187
|
+
defaults: {
|
|
188
|
+
tag: "Better Auth"
|
|
189
|
+
}
|
|
190
|
+
});
|
|
156
191
|
|
|
157
192
|
// src/error/better-auth-error.ts
|
|
158
193
|
var BetterAuthError = class extends Error {
|
|
159
|
-
constructor(message, cause
|
|
194
|
+
constructor(message, cause) {
|
|
160
195
|
super(message);
|
|
161
196
|
this.name = "BetterAuthError";
|
|
162
197
|
this.message = message;
|
|
@@ -164,15 +199,21 @@ var BetterAuthError = class extends Error {
|
|
|
164
199
|
this.stack = "";
|
|
165
200
|
}
|
|
166
201
|
};
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
function getSchema(modelName, schema) {
|
|
202
|
+
function getSchema(modelName, options) {
|
|
203
|
+
const schema = options.schema;
|
|
170
204
|
if (!schema) {
|
|
171
205
|
throw new BetterAuthError(
|
|
172
206
|
"Drizzle adapter failed to initialize. Schema not found. Please provide a schema object in the adapter options object."
|
|
173
207
|
);
|
|
174
208
|
}
|
|
175
|
-
|
|
209
|
+
const model = options.usePlural ? `${modelName}s` : modelName;
|
|
210
|
+
const schemaModel = schema[model];
|
|
211
|
+
if (!schemaModel) {
|
|
212
|
+
throw new BetterAuthError(
|
|
213
|
+
`[# Drizzle Adapter]: The model "${modelName}" was not found in the schema object. Please pass the schema directly to the adapter options.`
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
return schemaModel;
|
|
176
217
|
}
|
|
177
218
|
function whereConvertor(where, schemaModel) {
|
|
178
219
|
if (!where) return [];
|
|
@@ -207,13 +248,19 @@ var drizzleAdapter = (db, options) => {
|
|
|
207
248
|
id: "drizzle",
|
|
208
249
|
async create(data) {
|
|
209
250
|
const { model, data: val } = data;
|
|
210
|
-
const schemaModel = getSchema(model,
|
|
251
|
+
const schemaModel = getSchema(model, {
|
|
252
|
+
schema,
|
|
253
|
+
usePlural: options.usePlural
|
|
254
|
+
});
|
|
211
255
|
const res = await db.insert(schemaModel).values(val).returning();
|
|
212
256
|
return res[0];
|
|
213
257
|
},
|
|
214
258
|
async findOne(data) {
|
|
215
259
|
const { model, where, select: included } = data;
|
|
216
|
-
const schemaModel = getSchema(model,
|
|
260
|
+
const schemaModel = getSchema(model, {
|
|
261
|
+
schema,
|
|
262
|
+
usePlural: options.usePlural
|
|
263
|
+
});
|
|
217
264
|
const wheres = whereConvertor(where, schemaModel);
|
|
218
265
|
let res = null;
|
|
219
266
|
if (!!included?.length) {
|
|
@@ -232,23 +279,33 @@ var drizzleAdapter = (db, options) => {
|
|
|
232
279
|
},
|
|
233
280
|
async findMany(data) {
|
|
234
281
|
const { model, where } = data;
|
|
235
|
-
const schemaModel = getSchema(model,
|
|
282
|
+
const schemaModel = getSchema(model, {
|
|
283
|
+
schema,
|
|
284
|
+
usePlural: options.usePlural
|
|
285
|
+
});
|
|
236
286
|
const wheres = where ? whereConvertor(where, schemaModel) : [];
|
|
237
287
|
if (!wheres.length) {
|
|
238
288
|
return await db.select().from(schemaModel);
|
|
239
289
|
}
|
|
240
|
-
|
|
290
|
+
const res = await db.select().from(schemaModel).where(...wheres);
|
|
291
|
+
return res;
|
|
241
292
|
},
|
|
242
293
|
async update(data) {
|
|
243
294
|
const { model, where, update } = data;
|
|
244
|
-
const schemaModel = getSchema(model,
|
|
295
|
+
const schemaModel = getSchema(model, {
|
|
296
|
+
schema,
|
|
297
|
+
usePlural: options.usePlural
|
|
298
|
+
});
|
|
245
299
|
const wheres = whereConvertor(where, schemaModel);
|
|
246
300
|
const res = await db.update(schemaModel).set(update).where(...wheres).returning();
|
|
247
301
|
return res[0];
|
|
248
302
|
},
|
|
249
303
|
async delete(data) {
|
|
250
304
|
const { model, where } = data;
|
|
251
|
-
const schemaModel = getSchema(model,
|
|
305
|
+
const schemaModel = getSchema(model, {
|
|
306
|
+
schema,
|
|
307
|
+
usePlural: options.usePlural
|
|
308
|
+
});
|
|
252
309
|
const wheres = whereConvertor(where, schemaModel);
|
|
253
310
|
const res = await db.delete(schemaModel).where(...wheres);
|
|
254
311
|
return res[0];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { W as Where } from '../index-
|
|
1
|
+
import { W as Where } from '../index-DFyIXQyt.js';
|
|
2
2
|
import 'kysely';
|
|
3
|
-
import '../index-
|
|
3
|
+
import '../index-JM-i6hLs.js';
|
|
4
4
|
import 'arctic';
|
|
5
5
|
import 'zod';
|
|
6
|
-
import '../helper-
|
|
6
|
+
import '../helper-DPDj8Nix.js';
|
|
7
7
|
import 'better-call';
|
|
8
8
|
import 'better-sqlite3';
|
|
9
9
|
import 'mysql2';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { A as Adapter } from '../index-
|
|
1
|
+
import { A as Adapter } from '../index-DFyIXQyt.js';
|
|
2
2
|
import 'kysely';
|
|
3
|
-
import '../index-
|
|
3
|
+
import '../index-JM-i6hLs.js';
|
|
4
4
|
import 'arctic';
|
|
5
5
|
import 'zod';
|
|
6
|
-
import '../helper-
|
|
6
|
+
import '../helper-DPDj8Nix.js';
|
|
7
7
|
import 'better-call';
|
|
8
8
|
import 'better-sqlite3';
|
|
9
9
|
import 'mysql2';
|
package/dist/adapters/prisma.js
CHANGED
|
@@ -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 '
|
|
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,
|
|
1
|
+
export { b as AuthEndpoint, d as AuthMiddleware, y as callbackOAuth, X as changePassword, a as createAuthEndpoint, c as createAuthMiddleware, Q as createEmailVerificationToken, a2 as csrfMiddleware, Z as deleteUser, $ as error, M as forgetPassword, N as forgetPasswordCallback, _ as getCSRFToken, u as getEndpoints, z as getSession, C as getSessionFromCtx, E as listSessions, a0 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, a1 as signUpEmail, V as updateUser, U as verifyEmail } from './index-DFyIXQyt.js';
|
|
2
2
|
import 'zod';
|
|
3
|
-
import './helper-
|
|
3
|
+
import './helper-DPDj8Nix.js';
|
|
4
4
|
import 'better-call';
|
|
5
5
|
import 'kysely';
|
|
6
|
-
import './index-
|
|
6
|
+
import './index-JM-i6hLs.js';
|
|
7
7
|
import 'arctic';
|
|
8
8
|
import 'better-sqlite3';
|
|
9
9
|
import 'mysql2';
|