@auth/drizzle-adapter 1.4.1 → 1.5.0
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/lib/mysql.d.ts +11 -3
- package/lib/mysql.d.ts.map +1 -1
- package/lib/mysql.js +16 -14
- package/lib/pg.d.ts +11 -3
- package/lib/pg.d.ts.map +1 -1
- package/lib/pg.js +5 -4
- package/lib/sqlite.d.ts +9 -1
- package/lib/sqlite.d.ts.map +1 -1
- package/lib/sqlite.js +12 -11
- package/lib/utils.d.ts +4 -5
- package/lib/utils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/lib/mysql.ts +41 -21
- package/src/lib/pg.ts +31 -15
- package/src/lib/sqlite.ts +48 -32
- package/src/lib/utils.ts +4 -5
package/lib/mysql.d.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GeneratedColumnConfig } from "drizzle-orm";
|
|
2
|
+
import { MySqlColumn, MySqlDatabase, PreparedQueryHKTBase, MySqlTableWithColumns, MySqlQueryResultHKT } from "drizzle-orm/mysql-core";
|
|
2
3
|
import type { Adapter } from "@auth/core/adapters";
|
|
3
4
|
export declare function defineTables(schema?: Partial<DefaultMySqlSchema>): Required<DefaultMySqlSchema>;
|
|
4
|
-
export declare function MySqlDrizzleAdapter(client: MySqlDatabase<
|
|
5
|
+
export declare function MySqlDrizzleAdapter(client: MySqlDatabase<MySqlQueryResultHKT, PreparedQueryHKTBase, any>, schema?: DefaultMySqlSchema): Adapter;
|
|
5
6
|
type DefaultMyqlColumn<T extends {
|
|
6
7
|
data: string | number | boolean | Date;
|
|
7
8
|
dataType: "string" | "number" | "boolean" | "date";
|
|
8
9
|
notNull: boolean;
|
|
10
|
+
isPrimaryKey?: boolean;
|
|
9
11
|
columnType: "MySqlVarChar" | "MySqlText" | "MySqlBoolean" | "MySqlTimestamp" | "MySqlInt";
|
|
10
12
|
}> = MySqlColumn<{
|
|
13
|
+
isAutoincrement: boolean;
|
|
14
|
+
isPrimaryKey: T["isPrimaryKey"] extends true ? true : false;
|
|
15
|
+
hasRuntimeDefault: boolean;
|
|
16
|
+
generated: GeneratedColumnConfig<T["data"]> | undefined;
|
|
11
17
|
name: string;
|
|
12
18
|
columnType: T["columnType"];
|
|
13
19
|
data: T["data"];
|
|
@@ -22,6 +28,7 @@ export type DefaultMySqlUsersTable = MySqlTableWithColumns<{
|
|
|
22
28
|
name: string;
|
|
23
29
|
columns: {
|
|
24
30
|
id: DefaultMyqlColumn<{
|
|
31
|
+
isPrimaryKey: true;
|
|
25
32
|
data: string;
|
|
26
33
|
dataType: "string";
|
|
27
34
|
notNull: true;
|
|
@@ -36,7 +43,7 @@ export type DefaultMySqlUsersTable = MySqlTableWithColumns<{
|
|
|
36
43
|
email: DefaultMyqlColumn<{
|
|
37
44
|
data: string;
|
|
38
45
|
dataType: "string";
|
|
39
|
-
notNull:
|
|
46
|
+
notNull: boolean;
|
|
40
47
|
columnType: "MySqlVarChar" | "MySqlText";
|
|
41
48
|
}>;
|
|
42
49
|
emailVerified: DefaultMyqlColumn<{
|
|
@@ -133,6 +140,7 @@ export type DefaultMySqlSessionsTable = MySqlTableWithColumns<{
|
|
|
133
140
|
name: string;
|
|
134
141
|
columns: {
|
|
135
142
|
sessionToken: DefaultMyqlColumn<{
|
|
143
|
+
isPrimaryKey: true;
|
|
136
144
|
columnType: "MySqlVarChar" | "MySqlText";
|
|
137
145
|
data: string;
|
|
138
146
|
notNull: true;
|
package/lib/mysql.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../src/lib/mysql.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../src/lib/mysql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAA4B,MAAM,aAAa,CAAA;AAC7E,OAAO,EACL,WAAW,EACX,aAAa,EAOb,oB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SACnB,CAAC,CAAA;QACF,kBAAkB,EAAE,iBAAiB,CAAC;YACpC,UAAU,EAAE,cAAc,CAAA;YAC1B,IAAI,EAAE,OAAO,CAAA;YACb,OAAO,EAAE,IAAI,CAAA;YACb,QAAQ,EAAE,SAAS,CAAA;SACpB,CAAC,CAAA;QACF,UAAU,EAAE,iBAAiB,CAAC;YAC5B,UAAU,EAAE,cAAc,GAAG,WAAW,CAAA;YACxC,IAAI,EAAE,MAAM,CAAA;YACZ,OAAO,EAAE,KAAK,CAAA;YACd,QAAQ,EAAE,QAAQ,CAAA;SACnB,CAAC,CAAA;KACH,CAAA;IACD,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;CAC3B,CAAC,CAAA;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,sBAAsB,CAAA;IAClC,aAAa,EAAE,yBAAyB,CAAA;IACxC,aAAa,CAAC,EAAE,yBAAyB,CAAA;IACzC,uBAAuB,CAAC,EAAE,kCAAkC,CAAA;IAC5D,mBAAmB,CAAC,EAAE,8BAA8B,CAAA;CACrD,CAAA"}
|
package/lib/mysql.js
CHANGED
|
@@ -7,7 +7,7 @@ export function defineTables(schema = {}) {
|
|
|
7
7
|
.primaryKey()
|
|
8
8
|
.$defaultFn(() => crypto.randomUUID()),
|
|
9
9
|
name: varchar("name", { length: 255 }),
|
|
10
|
-
email: varchar("email", { length: 255 }).
|
|
10
|
+
email: varchar("email", { length: 255 }).unique(),
|
|
11
11
|
emailVerified: timestamp("emailVerified", { mode: "date", fsp: 3 }),
|
|
12
12
|
image: varchar("image", { length: 255 }),
|
|
13
13
|
}));
|
|
@@ -91,14 +91,15 @@ export function MySqlDrizzleAdapter(client, schema) {
|
|
|
91
91
|
return {
|
|
92
92
|
async createUser(data) {
|
|
93
93
|
const { id, ...insertData } = data;
|
|
94
|
-
const hasDefaultId = getTableColumns(usersTable)["id"]["
|
|
95
|
-
await client
|
|
94
|
+
const hasDefaultId = getTableColumns(usersTable)["id"]["defaultFn"];
|
|
95
|
+
const [insertedUser] = (await client
|
|
96
96
|
.insert(usersTable)
|
|
97
|
-
.values(hasDefaultId ? insertData : { ...insertData, id })
|
|
97
|
+
.values(hasDefaultId ? insertData : { ...insertData, id })
|
|
98
|
+
.$returningId());
|
|
98
99
|
return client
|
|
99
100
|
.select()
|
|
100
101
|
.from(usersTable)
|
|
101
|
-
.where(eq(usersTable.
|
|
102
|
+
.where(eq(usersTable.id, insertedUser ? insertedUser.id : id))
|
|
102
103
|
.then((res) => res[0]);
|
|
103
104
|
},
|
|
104
105
|
async getUser(userId) {
|
|
@@ -106,14 +107,14 @@ export function MySqlDrizzleAdapter(client, schema) {
|
|
|
106
107
|
.select()
|
|
107
108
|
.from(usersTable)
|
|
108
109
|
.where(eq(usersTable.id, userId))
|
|
109
|
-
.then((res) =>
|
|
110
|
+
.then((res) => res.length > 0 ? res[0] : null);
|
|
110
111
|
},
|
|
111
112
|
async getUserByEmail(email) {
|
|
112
113
|
return client
|
|
113
114
|
.select()
|
|
114
115
|
.from(usersTable)
|
|
115
116
|
.where(eq(usersTable.email, email))
|
|
116
|
-
.then((res) =>
|
|
117
|
+
.then((res) => res.length > 0 ? res[0] : null);
|
|
117
118
|
},
|
|
118
119
|
async createSession(data) {
|
|
119
120
|
await client.insert(sessionsTable).values(data);
|
|
@@ -175,7 +176,8 @@ export function MySqlDrizzleAdapter(client, schema) {
|
|
|
175
176
|
.innerJoin(usersTable, eq(accountsTable.userId, usersTable.id))
|
|
176
177
|
.where(and(eq(accountsTable.provider, account.provider), eq(accountsTable.providerAccountId, account.providerAccountId)))
|
|
177
178
|
.then((res) => res[0]);
|
|
178
|
-
|
|
179
|
+
const user = result?.user ?? null;
|
|
180
|
+
return user;
|
|
179
181
|
},
|
|
180
182
|
async deleteSession(sessionToken) {
|
|
181
183
|
await client
|
|
@@ -220,25 +222,25 @@ export function MySqlDrizzleAdapter(client, schema) {
|
|
|
220
222
|
},
|
|
221
223
|
async createAuthenticator(data) {
|
|
222
224
|
await client.insert(authenticatorsTable).values(data);
|
|
223
|
-
return await client
|
|
225
|
+
return (await client
|
|
224
226
|
.select()
|
|
225
227
|
.from(authenticatorsTable)
|
|
226
228
|
.where(eq(authenticatorsTable.credentialID, data.credentialID))
|
|
227
|
-
.then((res) => res[0] ?? null);
|
|
229
|
+
.then((res) => res[0] ?? null));
|
|
228
230
|
},
|
|
229
231
|
async getAuthenticator(credentialID) {
|
|
230
|
-
return await client
|
|
232
|
+
return (await client
|
|
231
233
|
.select()
|
|
232
234
|
.from(authenticatorsTable)
|
|
233
235
|
.where(eq(authenticatorsTable.credentialID, credentialID))
|
|
234
|
-
.then((res) => res[0] ?? null);
|
|
236
|
+
.then((res) => res[0] ?? null));
|
|
235
237
|
},
|
|
236
238
|
async listAuthenticatorsByUserId(userId) {
|
|
237
|
-
return await client
|
|
239
|
+
return (await client
|
|
238
240
|
.select()
|
|
239
241
|
.from(authenticatorsTable)
|
|
240
242
|
.where(eq(authenticatorsTable.userId, userId))
|
|
241
|
-
.then((res) => res);
|
|
243
|
+
.then((res) => res));
|
|
242
244
|
},
|
|
243
245
|
async updateAuthenticatorCounter(credentialID, newCounter) {
|
|
244
246
|
await client
|
package/lib/pg.d.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GeneratedColumnConfig } from "drizzle-orm";
|
|
2
|
+
import { PgColumn, PgDatabase, PgQueryResultHKT, PgTableWithColumns } from "drizzle-orm/pg-core";
|
|
2
3
|
import type { Adapter } from "@auth/core/adapters";
|
|
3
4
|
export declare function defineTables(schema?: Partial<DefaultPostgresSchema>): Required<DefaultPostgresSchema>;
|
|
4
|
-
export declare function PostgresDrizzleAdapter(client: PgDatabase<
|
|
5
|
+
export declare function PostgresDrizzleAdapter(client: PgDatabase<PgQueryResultHKT, any>, schema?: DefaultPostgresSchema): Adapter;
|
|
5
6
|
type DefaultPostgresColumn<T extends {
|
|
6
7
|
data: string | number | boolean | Date;
|
|
7
8
|
dataType: "string" | "number" | "boolean" | "date";
|
|
8
9
|
notNull: boolean;
|
|
10
|
+
isPrimaryKey?: boolean;
|
|
9
11
|
columnType: "PgVarchar" | "PgText" | "PgBoolean" | "PgTimestamp" | "PgInteger" | "PgUUID";
|
|
10
12
|
}> = PgColumn<{
|
|
11
13
|
name: string;
|
|
14
|
+
isAutoincrement: boolean;
|
|
15
|
+
isPrimaryKey: T["isPrimaryKey"] extends true ? true : false;
|
|
16
|
+
hasRuntimeDefault: boolean;
|
|
17
|
+
generated: GeneratedColumnConfig<T["data"]> | undefined;
|
|
12
18
|
columnType: T["columnType"];
|
|
13
19
|
data: T["data"];
|
|
14
20
|
driverParam: string | number | boolean;
|
|
@@ -23,6 +29,7 @@ export type DefaultPostgresUsersTable = PgTableWithColumns<{
|
|
|
23
29
|
columns: {
|
|
24
30
|
id: DefaultPostgresColumn<{
|
|
25
31
|
columnType: "PgVarchar" | "PgText" | "PgUUID";
|
|
32
|
+
isPrimaryKey: true;
|
|
26
33
|
data: string;
|
|
27
34
|
notNull: true;
|
|
28
35
|
dataType: "string";
|
|
@@ -36,7 +43,7 @@ export type DefaultPostgresUsersTable = PgTableWithColumns<{
|
|
|
36
43
|
email: DefaultPostgresColumn<{
|
|
37
44
|
columnType: "PgVarchar" | "PgText";
|
|
38
45
|
data: string;
|
|
39
|
-
notNull:
|
|
46
|
+
notNull: boolean;
|
|
40
47
|
dataType: "string";
|
|
41
48
|
}>;
|
|
42
49
|
emailVerified: DefaultPostgresColumn<{
|
|
@@ -134,6 +141,7 @@ export type DefaultPostgresSessionsTable = PgTableWithColumns<{
|
|
|
134
141
|
sessionToken: DefaultPostgresColumn<{
|
|
135
142
|
columnType: "PgVarchar" | "PgText";
|
|
136
143
|
data: string;
|
|
144
|
+
isPrimaryKey: true;
|
|
137
145
|
notNull: true;
|
|
138
146
|
dataType: "string";
|
|
139
147
|
}>;
|
package/lib/pg.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pg.d.ts","sourceRoot":"","sources":["../src/lib/pg.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pg.d.ts","sourceRoot":"","sources":["../src/lib/pg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAA4B,MAAM,aAAa,CAAA;AAC7E,OAAO,EACL,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAOnB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,KAAK,EACV,OAAO,EAOR,MAAM,qBAAqB,CAAA;AAG5B,wBAAgB,YAAY,CAC1B,MAAM,GAAE,OAAO,CAAC,qBAAqB,CAAM,GAC1C,QAAQ,CAAC,qBAAqB,CAAC,CA+FjC;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,UAAU,CAAC,gBAAgB,EAAE,GAAG,CAAC,EACzC,MAAM,CAAC,EAAE,qBAAqB,GAC7B,OAAO,CAuMT;AAED,KAAK,qBAAqB,CACxB,CAAC,SAAS;IACR,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;IACtC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAA;IAClD,OAAO,EAAE,OAAO,CAAA;IAChB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,UAAU,EACN,WAAW,GACX,QAAQ,GACR,WAAW,GACX,aAAa,GACb,WAAW,GACX,QAAQ,CAAA;CACb,IACC,QAAQ,CAAC;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,eAAe,EAAE,OAAO,CAAA;IACxB,YAAY,EAAE,CAAC,CAAC,cAAc,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,KAAK,CAAA;IAC3D,iBAAiB,EAAE,OAAO,CAAA;IAC1B,SAAS,EAAE,qBAAqB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAA;IACvD,UAAU,E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,EAAE,MAAM,CAAA;YACZ,OAAO,EAAE,IAAI,CAAA;YACb,QAAQ,EAAE,QAAQ,CAAA;SACnB,CAAC,CAAA;QACF,oBAAoB,EAAE,qBAAqB,CAAC;YAC1C,UAAU,EAAE,WAAW,GAAG,QAAQ,CAAA;YAClC,IAAI,EAAE,MAAM,CAAA;YACZ,OAAO,EAAE,IAAI,CAAA;YACb,QAAQ,EAAE,QAAQ,CAAA;SACnB,CAAC,CAAA;QACF,kBAAkB,EAAE,qBAAqB,CAAC;YACxC,UAAU,EAAE,WAAW,CAAA;YACvB,IAAI,EAAE,OAAO,CAAA;YACb,OAAO,EAAE,IAAI,CAAA;YACb,QAAQ,EAAE,SAAS,CAAA;SACpB,CAAC,CAAA;QACF,UAAU,EAAE,qBAAqB,CAAC;YAChC,UAAU,EAAE,WAAW,GAAG,QAAQ,CAAA;YAClC,IAAI,EAAE,MAAM,CAAA;YACZ,OAAO,EAAE,KAAK,CAAA;YACd,QAAQ,EAAE,QAAQ,CAAA;SACnB,CAAC,CAAA;KACH,CAAA;IACD,OAAO,EAAE,IAAI,CAAA;IACb,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;CAC3B,CAAC,CAAA;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,UAAU,EAAE,yBAAyB,CAAA;IACrC,aAAa,EAAE,4BAA4B,CAAA;IAC3C,aAAa,CAAC,EAAE,4BAA4B,CAAA;IAC5C,uBAAuB,CAAC,EAAE,qCAAqC,CAAA;IAC/D,mBAAmB,CAAC,EAAE,iCAAiC,CAAA;CACxD,CAAA"}
|
package/lib/pg.js
CHANGED
|
@@ -7,7 +7,7 @@ export function defineTables(schema = {}) {
|
|
|
7
7
|
.primaryKey()
|
|
8
8
|
.$defaultFn(() => crypto.randomUUID()),
|
|
9
9
|
name: text("name"),
|
|
10
|
-
email: text("email").
|
|
10
|
+
email: text("email").unique(),
|
|
11
11
|
emailVerified: timestamp("emailVerified", { mode: "date" }),
|
|
12
12
|
image: text("image"),
|
|
13
13
|
}));
|
|
@@ -91,14 +91,14 @@ export function PostgresDrizzleAdapter(client, schema) {
|
|
|
91
91
|
.select()
|
|
92
92
|
.from(usersTable)
|
|
93
93
|
.where(eq(usersTable.id, userId))
|
|
94
|
-
.then((res) =>
|
|
94
|
+
.then((res) => res.length > 0 ? res[0] : null);
|
|
95
95
|
},
|
|
96
96
|
async getUserByEmail(email) {
|
|
97
97
|
return client
|
|
98
98
|
.select()
|
|
99
99
|
.from(usersTable)
|
|
100
100
|
.where(eq(usersTable.email, email))
|
|
101
|
-
.then((res) =>
|
|
101
|
+
.then((res) => res.length > 0 ? res[0] : null);
|
|
102
102
|
},
|
|
103
103
|
async createSession(data) {
|
|
104
104
|
return client
|
|
@@ -153,7 +153,8 @@ export function PostgresDrizzleAdapter(client, schema) {
|
|
|
153
153
|
.innerJoin(usersTable, eq(accountsTable.userId, usersTable.id))
|
|
154
154
|
.where(and(eq(accountsTable.provider, account.provider), eq(accountsTable.providerAccountId, account.providerAccountId)))
|
|
155
155
|
.then((res) => res[0]);
|
|
156
|
-
|
|
156
|
+
const user = result?.user ?? null;
|
|
157
|
+
return user;
|
|
157
158
|
},
|
|
158
159
|
async deleteSession(sessionToken) {
|
|
159
160
|
await client
|
package/lib/sqlite.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GeneratedColumnConfig } from "drizzle-orm";
|
|
1
2
|
import { BaseSQLiteDatabase, SQLiteColumn, SQLiteTableWithColumns } from "drizzle-orm/sqlite-core";
|
|
2
3
|
import type { Adapter } from "@auth/core/adapters";
|
|
3
4
|
export declare function defineTables(schema?: Partial<DefaultSQLiteSchema>): Required<DefaultSQLiteSchema>;
|
|
@@ -6,9 +7,14 @@ type DefaultSQLiteColumn<T extends {
|
|
|
6
7
|
data: string | boolean | number | Date;
|
|
7
8
|
dataType: "string" | "boolean" | "number" | "date";
|
|
8
9
|
notNull: boolean;
|
|
10
|
+
isPrimaryKey?: boolean;
|
|
9
11
|
columnType: "SQLiteText" | "SQLiteBoolean" | "SQLiteTimestamp" | "SQLiteInteger";
|
|
10
12
|
}> = SQLiteColumn<{
|
|
11
13
|
name: string;
|
|
14
|
+
isAutoincrement: boolean;
|
|
15
|
+
isPrimaryKey: T["isPrimaryKey"] extends true ? true : false;
|
|
16
|
+
hasRuntimeDefault: boolean;
|
|
17
|
+
generated: GeneratedColumnConfig<T["data"]> | undefined;
|
|
12
18
|
columnType: T["columnType"];
|
|
13
19
|
data: T["data"];
|
|
14
20
|
driverParam: string | number | boolean;
|
|
@@ -24,6 +30,7 @@ export type DefaultSQLiteUsersTable = SQLiteTableWithColumns<{
|
|
|
24
30
|
id: DefaultSQLiteColumn<{
|
|
25
31
|
columnType: "SQLiteText";
|
|
26
32
|
data: string;
|
|
33
|
+
isPrimaryKey: true;
|
|
27
34
|
notNull: true;
|
|
28
35
|
dataType: "string";
|
|
29
36
|
}>;
|
|
@@ -36,7 +43,7 @@ export type DefaultSQLiteUsersTable = SQLiteTableWithColumns<{
|
|
|
36
43
|
email: DefaultSQLiteColumn<{
|
|
37
44
|
columnType: "SQLiteText";
|
|
38
45
|
data: string;
|
|
39
|
-
notNull:
|
|
46
|
+
notNull: boolean;
|
|
40
47
|
dataType: "string";
|
|
41
48
|
}>;
|
|
42
49
|
emailVerified: DefaultSQLiteColumn<{
|
|
@@ -134,6 +141,7 @@ export type DefaultSQLiteSessionsTable = SQLiteTableWithColumns<{
|
|
|
134
141
|
sessionToken: DefaultSQLiteColumn<{
|
|
135
142
|
columnType: "SQLiteText";
|
|
136
143
|
data: string;
|
|
144
|
+
isPrimaryKey: true;
|
|
137
145
|
notNull: true;
|
|
138
146
|
dataType: "string";
|
|
139
147
|
}>;
|
package/lib/sqlite.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../src/lib/sqlite.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sourceRo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U,EAAE,mBAAmB,CAAC;YAC9B,UAAU,EAAE,YAAY,CAAA;YACxB,IAAI,EAAE,MAAM,CAAA;YACZ,OAAO,EAAE,KAAK,CAAA;YACd,QAAQ,EAAE,QAAQ,CAAA;SACnB,CAAC,CAAA;KACH,CAAA;IACD,OAAO,EAAE,QAAQ,CAAA;IACjB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;CAC3B,CAAC,CAAA;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,UAAU,EAAE,uBAAuB,CAAA;IACnC,aAAa,EAAE,0BAA0B,CAAA;IACzC,aAAa,CAAC,EAAE,0BAA0B,CAAA;IAC1C,uBAAuB,CAAC,EAAE,mCAAmC,CAAA;IAC7D,mBAAmB,CAAC,EAAE,+BAA+B,CAAA;CACtD,CAAA"}
|
package/lib/sqlite.js
CHANGED
|
@@ -7,7 +7,7 @@ export function defineTables(schema = {}) {
|
|
|
7
7
|
.primaryKey()
|
|
8
8
|
.$defaultFn(() => crypto.randomUUID()),
|
|
9
9
|
name: text("name"),
|
|
10
|
-
email: text("email").
|
|
10
|
+
email: text("email").unique(),
|
|
11
11
|
emailVerified: integer("emailVerified", { mode: "timestamp_ms" }),
|
|
12
12
|
image: text("image"),
|
|
13
13
|
}));
|
|
@@ -89,26 +89,26 @@ export function SQLiteDrizzleAdapter(client, schema) {
|
|
|
89
89
|
.get();
|
|
90
90
|
},
|
|
91
91
|
async getUser(userId) {
|
|
92
|
-
const result = await client
|
|
92
|
+
const result = (await client
|
|
93
93
|
.select()
|
|
94
94
|
.from(usersTable)
|
|
95
95
|
.where(eq(usersTable.id, userId))
|
|
96
|
-
.get();
|
|
97
|
-
return result
|
|
96
|
+
.get()) ?? null;
|
|
97
|
+
return result;
|
|
98
98
|
},
|
|
99
99
|
async getUserByEmail(email) {
|
|
100
|
-
const result = await client
|
|
100
|
+
const result = (await client
|
|
101
101
|
.select()
|
|
102
102
|
.from(usersTable)
|
|
103
103
|
.where(eq(usersTable.email, email))
|
|
104
|
-
.get();
|
|
105
|
-
return result
|
|
104
|
+
.get()) ?? null;
|
|
105
|
+
return result;
|
|
106
106
|
},
|
|
107
107
|
async createSession(data) {
|
|
108
108
|
return client.insert(sessionsTable).values(data).returning().get();
|
|
109
109
|
},
|
|
110
110
|
async getSessionAndUser(sessionToken) {
|
|
111
|
-
const result = await client
|
|
111
|
+
const result = (await client
|
|
112
112
|
.select({
|
|
113
113
|
session: sessionsTable,
|
|
114
114
|
user: usersTable,
|
|
@@ -116,8 +116,8 @@ export function SQLiteDrizzleAdapter(client, schema) {
|
|
|
116
116
|
.from(sessionsTable)
|
|
117
117
|
.where(eq(sessionsTable.sessionToken, sessionToken))
|
|
118
118
|
.innerJoin(usersTable, eq(usersTable.id, sessionsTable.userId))
|
|
119
|
-
.get();
|
|
120
|
-
return result
|
|
119
|
+
.get()) ?? null;
|
|
120
|
+
return result;
|
|
121
121
|
},
|
|
122
122
|
async updateUser(data) {
|
|
123
123
|
if (!data.id) {
|
|
@@ -156,7 +156,8 @@ export function SQLiteDrizzleAdapter(client, schema) {
|
|
|
156
156
|
.innerJoin(usersTable, eq(accountsTable.userId, usersTable.id))
|
|
157
157
|
.where(and(eq(accountsTable.provider, account.provider), eq(accountsTable.providerAccountId, account.providerAccountId)))
|
|
158
158
|
.get();
|
|
159
|
-
|
|
159
|
+
const user = result?.user ?? null;
|
|
160
|
+
return user;
|
|
160
161
|
},
|
|
161
162
|
async deleteSession(sessionToken) {
|
|
162
163
|
await client
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MySqlQueryResultHKT, PreparedQueryHKTBase } from "drizzle-orm/mysql-core";
|
|
2
2
|
import { MySqlDatabase } from "drizzle-orm/mysql-core";
|
|
3
|
-
import
|
|
4
|
-
import { PgDatabase } from "drizzle-orm/pg-core";
|
|
3
|
+
import { PgDatabase, PgQueryResultHKT } from "drizzle-orm/pg-core";
|
|
5
4
|
import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core";
|
|
6
5
|
import { DefaultMySqlSchema } from "./mysql.js";
|
|
7
6
|
import { DefaultPostgresSchema } from "./pg.js";
|
|
8
7
|
import { DefaultSQLiteSchema } from "./sqlite.js";
|
|
9
|
-
type AnyPostgresDatabase = PgDatabase<
|
|
10
|
-
type AnyMySqlDatabase = MySqlDatabase<
|
|
8
|
+
type AnyPostgresDatabase = PgDatabase<PgQueryResultHKT, any>;
|
|
9
|
+
type AnyMySqlDatabase = MySqlDatabase<MySqlQueryResultHKT, PreparedQueryHKTBase, any>;
|
|
11
10
|
type AnySQLiteDatabase = BaseSQLiteDatabase<"sync" | "async", any, any>;
|
|
12
11
|
export type SqlFlavorOptions = AnyPostgresDatabase | AnyMySqlDatabase | AnySQLiteDatabase;
|
|
13
12
|
export type DefaultSchema<Flavor extends SqlFlavorOptions> = Flavor extends AnyMySqlDatabase ? DefaultMySqlSchema : Flavor extends AnyPostgresDatabase ? DefaultPostgresSchema : Flavor extends AnySQLiteDatabase ? DefaultSQLiteSchema : never;
|
package/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEjD,KAAK,mBAAmB,GAAG,UAAU,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAA;AAC5D,KAAK,gBAAgB,GAAG,aAAa,CACnC,mBAAmB,EACnB,oBAAoB,EACpB,GAAG,CACJ,CAAA;AACD,KAAK,iBAAiB,GAAG,kBAAkB,CAAC,MAAM,GAAG,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAEvE,MAAM,MAAM,gBAAgB,GACxB,mBAAmB,GACnB,gBAAgB,GAChB,iBAAiB,CAAA;AAErB,MAAM,MAAM,aAAa,CAAC,MAAM,SAAS,gBAAgB,IACvD,MAAM,SAAS,gBAAgB,GAC3B,kBAAkB,GAClB,MAAM,SAAS,mBAAmB,GAChC,qBAAqB,GACrB,MAAM,SAAS,iBAAiB,GAC9B,mBAAmB,GACnB,KAAK,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auth/drizzle-adapter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Drizzle adapter for Auth.js.",
|
|
5
5
|
"homepage": "https://authjs.dev",
|
|
6
6
|
"repository": "https://github.com/nextauthjs/next-auth",
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@auth/core": "0.
|
|
40
|
+
"@auth/core": "0.35.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/uuid": "^8.3.3",
|
|
44
|
-
"drizzle-kit": "^0.
|
|
45
|
-
"drizzle-orm": "^0.
|
|
44
|
+
"drizzle-kit": "^0.23.0",
|
|
45
|
+
"drizzle-orm": "^0.32.0",
|
|
46
46
|
"libsql": "^0.3.18",
|
|
47
47
|
"mysql2": "^3.9.7",
|
|
48
48
|
"postgres": "^3.4.3",
|
package/src/lib/mysql.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { and, eq, getTableColumns } from "drizzle-orm"
|
|
1
|
+
import { GeneratedColumnConfig, and, eq, getTableColumns } from "drizzle-orm"
|
|
2
2
|
import {
|
|
3
3
|
MySqlColumn,
|
|
4
4
|
MySqlDatabase,
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
primaryKey,
|
|
9
9
|
timestamp,
|
|
10
10
|
varchar,
|
|
11
|
-
QueryResultHKT,
|
|
12
11
|
PreparedQueryHKTBase,
|
|
13
12
|
MySqlTableWithColumns,
|
|
13
|
+
MySqlQueryResultHKT,
|
|
14
14
|
} from "drizzle-orm/mysql-core"
|
|
15
15
|
|
|
16
16
|
import type {
|
|
@@ -22,6 +22,7 @@ import type {
|
|
|
22
22
|
VerificationToken,
|
|
23
23
|
AdapterAuthenticator,
|
|
24
24
|
} from "@auth/core/adapters"
|
|
25
|
+
import { Awaitable } from "@auth/core/types"
|
|
25
26
|
|
|
26
27
|
export function defineTables(
|
|
27
28
|
schema: Partial<DefaultMySqlSchema> = {}
|
|
@@ -33,7 +34,7 @@ export function defineTables(
|
|
|
33
34
|
.primaryKey()
|
|
34
35
|
.$defaultFn(() => crypto.randomUUID()),
|
|
35
36
|
name: varchar("name", { length: 255 }),
|
|
36
|
-
email: varchar("email", { length: 255 }).
|
|
37
|
+
email: varchar("email", { length: 255 }).unique(),
|
|
37
38
|
emailVerified: timestamp("emailVerified", { mode: "date", fsp: 3 }),
|
|
38
39
|
image: varchar("image", { length: 255 }),
|
|
39
40
|
}) satisfies DefaultMySqlUsersTable)
|
|
@@ -135,7 +136,7 @@ export function defineTables(
|
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
export function MySqlDrizzleAdapter(
|
|
138
|
-
client: MySqlDatabase<
|
|
139
|
+
client: MySqlDatabase<MySqlQueryResultHKT, PreparedQueryHKTBase, any>,
|
|
139
140
|
schema?: DefaultMySqlSchema
|
|
140
141
|
): Adapter {
|
|
141
142
|
const {
|
|
@@ -149,31 +150,36 @@ export function MySqlDrizzleAdapter(
|
|
|
149
150
|
return {
|
|
150
151
|
async createUser(data: AdapterUser) {
|
|
151
152
|
const { id, ...insertData } = data
|
|
152
|
-
const hasDefaultId = getTableColumns(usersTable)["id"]["
|
|
153
|
+
const hasDefaultId = getTableColumns(usersTable)["id"]["defaultFn"]
|
|
153
154
|
|
|
154
|
-
await client
|
|
155
|
+
const [insertedUser] = (await client
|
|
155
156
|
.insert(usersTable)
|
|
156
157
|
.values(hasDefaultId ? insertData : { ...insertData, id })
|
|
158
|
+
.$returningId()) as [{ id: string }] | []
|
|
157
159
|
|
|
158
160
|
return client
|
|
159
161
|
.select()
|
|
160
162
|
.from(usersTable)
|
|
161
|
-
.where(eq(usersTable.
|
|
162
|
-
.then((res) => res[0])
|
|
163
|
+
.where(eq(usersTable.id, insertedUser ? insertedUser.id : id))
|
|
164
|
+
.then((res) => res[0]) as Awaitable<AdapterUser>
|
|
163
165
|
},
|
|
164
166
|
async getUser(userId: string) {
|
|
165
167
|
return client
|
|
166
168
|
.select()
|
|
167
169
|
.from(usersTable)
|
|
168
170
|
.where(eq(usersTable.id, userId))
|
|
169
|
-
.then((res) =>
|
|
171
|
+
.then((res) =>
|
|
172
|
+
res.length > 0 ? res[0] : null
|
|
173
|
+
) as Awaitable<AdapterUser | null>
|
|
170
174
|
},
|
|
171
175
|
async getUserByEmail(email: string) {
|
|
172
176
|
return client
|
|
173
177
|
.select()
|
|
174
178
|
.from(usersTable)
|
|
175
179
|
.where(eq(usersTable.email, email))
|
|
176
|
-
.then((res) =>
|
|
180
|
+
.then((res) =>
|
|
181
|
+
res.length > 0 ? res[0] : null
|
|
182
|
+
) as Awaitable<AdapterUser | null>
|
|
177
183
|
},
|
|
178
184
|
async createSession(data: {
|
|
179
185
|
sessionToken: string
|
|
@@ -197,7 +203,10 @@ export function MySqlDrizzleAdapter(
|
|
|
197
203
|
.from(sessionsTable)
|
|
198
204
|
.where(eq(sessionsTable.sessionToken, sessionToken))
|
|
199
205
|
.innerJoin(usersTable, eq(usersTable.id, sessionsTable.userId))
|
|
200
|
-
.then((res) => (res.length > 0 ? res[0] : null))
|
|
206
|
+
.then((res) => (res.length > 0 ? res[0] : null)) as Awaitable<{
|
|
207
|
+
session: AdapterSession
|
|
208
|
+
user: AdapterUser
|
|
209
|
+
} | null>
|
|
201
210
|
},
|
|
202
211
|
async updateUser(data: Partial<AdapterUser> & Pick<AdapterUser, "id">) {
|
|
203
212
|
if (!data.id) {
|
|
@@ -218,7 +227,7 @@ export function MySqlDrizzleAdapter(
|
|
|
218
227
|
throw new Error("No user found.")
|
|
219
228
|
}
|
|
220
229
|
|
|
221
|
-
return result
|
|
230
|
+
return result as Awaitable<AdapterUser>
|
|
222
231
|
},
|
|
223
232
|
async updateSession(
|
|
224
233
|
data: Partial<AdapterSession> & Pick<AdapterSession, "sessionToken">
|
|
@@ -255,7 +264,9 @@ export function MySqlDrizzleAdapter(
|
|
|
255
264
|
)
|
|
256
265
|
.then((res) => res[0])
|
|
257
266
|
|
|
258
|
-
|
|
267
|
+
const user = result?.user ?? null
|
|
268
|
+
|
|
269
|
+
return user as Awaitable<AdapterUser | null>
|
|
259
270
|
},
|
|
260
271
|
async deleteSession(sessionToken: string) {
|
|
261
272
|
await client
|
|
@@ -326,25 +337,27 @@ export function MySqlDrizzleAdapter(
|
|
|
326
337
|
async createAuthenticator(data: AdapterAuthenticator) {
|
|
327
338
|
await client.insert(authenticatorsTable).values(data)
|
|
328
339
|
|
|
329
|
-
return await client
|
|
340
|
+
return (await client
|
|
330
341
|
.select()
|
|
331
342
|
.from(authenticatorsTable)
|
|
332
343
|
.where(eq(authenticatorsTable.credentialID, data.credentialID))
|
|
333
|
-
.then((res) => res[0] ?? null)
|
|
344
|
+
.then((res) => res[0] ?? null)) as Awaitable<AdapterAuthenticator>
|
|
334
345
|
},
|
|
335
346
|
async getAuthenticator(credentialID: string) {
|
|
336
|
-
return await client
|
|
347
|
+
return (await client
|
|
337
348
|
.select()
|
|
338
349
|
.from(authenticatorsTable)
|
|
339
350
|
.where(eq(authenticatorsTable.credentialID, credentialID))
|
|
340
|
-
.then(
|
|
351
|
+
.then(
|
|
352
|
+
(res) => res[0] ?? null
|
|
353
|
+
)) as Awaitable<AdapterAuthenticator | null>
|
|
341
354
|
},
|
|
342
355
|
async listAuthenticatorsByUserId(userId: string) {
|
|
343
|
-
return await client
|
|
356
|
+
return (await client
|
|
344
357
|
.select()
|
|
345
358
|
.from(authenticatorsTable)
|
|
346
359
|
.where(eq(authenticatorsTable.userId, userId))
|
|
347
|
-
.then((res) => res)
|
|
360
|
+
.then((res) => res)) as Awaitable<AdapterAuthenticator[]>
|
|
348
361
|
},
|
|
349
362
|
async updateAuthenticatorCounter(credentialID: string, newCounter: number) {
|
|
350
363
|
await client
|
|
@@ -360,7 +373,7 @@ export function MySqlDrizzleAdapter(
|
|
|
360
373
|
|
|
361
374
|
if (!authenticator) throw new Error("Authenticator not found.")
|
|
362
375
|
|
|
363
|
-
return authenticator
|
|
376
|
+
return authenticator as Awaitable<AdapterAuthenticator>
|
|
364
377
|
},
|
|
365
378
|
}
|
|
366
379
|
}
|
|
@@ -370,6 +383,7 @@ type DefaultMyqlColumn<
|
|
|
370
383
|
data: string | number | boolean | Date
|
|
371
384
|
dataType: "string" | "number" | "boolean" | "date"
|
|
372
385
|
notNull: boolean
|
|
386
|
+
isPrimaryKey?: boolean
|
|
373
387
|
columnType:
|
|
374
388
|
| "MySqlVarChar"
|
|
375
389
|
| "MySqlText"
|
|
@@ -378,6 +392,10 @@ type DefaultMyqlColumn<
|
|
|
378
392
|
| "MySqlInt"
|
|
379
393
|
},
|
|
380
394
|
> = MySqlColumn<{
|
|
395
|
+
isAutoincrement: boolean
|
|
396
|
+
isPrimaryKey: T["isPrimaryKey"] extends true ? true : false
|
|
397
|
+
hasRuntimeDefault: boolean
|
|
398
|
+
generated: GeneratedColumnConfig<T["data"]> | undefined
|
|
381
399
|
name: string
|
|
382
400
|
columnType: T["columnType"]
|
|
383
401
|
data: T["data"]
|
|
@@ -393,6 +411,7 @@ export type DefaultMySqlUsersTable = MySqlTableWithColumns<{
|
|
|
393
411
|
name: string
|
|
394
412
|
columns: {
|
|
395
413
|
id: DefaultMyqlColumn<{
|
|
414
|
+
isPrimaryKey: true
|
|
396
415
|
data: string
|
|
397
416
|
dataType: "string"
|
|
398
417
|
notNull: true
|
|
@@ -407,7 +426,7 @@ export type DefaultMySqlUsersTable = MySqlTableWithColumns<{
|
|
|
407
426
|
email: DefaultMyqlColumn<{
|
|
408
427
|
data: string
|
|
409
428
|
dataType: "string"
|
|
410
|
-
notNull:
|
|
429
|
+
notNull: boolean
|
|
411
430
|
columnType: "MySqlVarChar" | "MySqlText"
|
|
412
431
|
}>
|
|
413
432
|
emailVerified: DefaultMyqlColumn<{
|
|
@@ -506,6 +525,7 @@ export type DefaultMySqlSessionsTable = MySqlTableWithColumns<{
|
|
|
506
525
|
name: string
|
|
507
526
|
columns: {
|
|
508
527
|
sessionToken: DefaultMyqlColumn<{
|
|
528
|
+
isPrimaryKey: true
|
|
509
529
|
columnType: "MySqlVarChar" | "MySqlText"
|
|
510
530
|
data: string
|
|
511
531
|
notNull: true
|
package/src/lib/pg.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GeneratedColumnConfig, and, eq, getTableColumns } from "drizzle-orm"
|
|
2
2
|
import {
|
|
3
3
|
PgColumn,
|
|
4
4
|
PgDatabase,
|
|
5
|
+
PgQueryResultHKT,
|
|
5
6
|
PgTableWithColumns,
|
|
6
|
-
QueryResultHKT,
|
|
7
7
|
boolean,
|
|
8
8
|
integer,
|
|
9
9
|
pgTable,
|
|
@@ -21,6 +21,7 @@ import type {
|
|
|
21
21
|
AdapterUser,
|
|
22
22
|
VerificationToken,
|
|
23
23
|
} from "@auth/core/adapters"
|
|
24
|
+
import { Awaitable } from "@auth/core/types"
|
|
24
25
|
|
|
25
26
|
export function defineTables(
|
|
26
27
|
schema: Partial<DefaultPostgresSchema> = {}
|
|
@@ -32,7 +33,7 @@ export function defineTables(
|
|
|
32
33
|
.primaryKey()
|
|
33
34
|
.$defaultFn(() => crypto.randomUUID()),
|
|
34
35
|
name: text("name"),
|
|
35
|
-
email: text("email").
|
|
36
|
+
email: text("email").unique(),
|
|
36
37
|
emailVerified: timestamp("emailVerified", { mode: "date" }),
|
|
37
38
|
image: text("image"),
|
|
38
39
|
}) satisfies DefaultPostgresUsersTable)
|
|
@@ -122,7 +123,7 @@ export function defineTables(
|
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
export function PostgresDrizzleAdapter(
|
|
125
|
-
client: PgDatabase<
|
|
126
|
+
client: PgDatabase<PgQueryResultHKT, any>,
|
|
126
127
|
schema?: DefaultPostgresSchema
|
|
127
128
|
): Adapter {
|
|
128
129
|
const {
|
|
@@ -142,21 +143,25 @@ export function PostgresDrizzleAdapter(
|
|
|
142
143
|
.insert(usersTable)
|
|
143
144
|
.values(hasDefaultId ? insertData : { ...insertData, id })
|
|
144
145
|
.returning()
|
|
145
|
-
.then((res) => res[0])
|
|
146
|
+
.then((res) => res[0]) as Awaitable<AdapterUser>
|
|
146
147
|
},
|
|
147
148
|
async getUser(userId: string) {
|
|
148
149
|
return client
|
|
149
150
|
.select()
|
|
150
151
|
.from(usersTable)
|
|
151
152
|
.where(eq(usersTable.id, userId))
|
|
152
|
-
.then((res) =>
|
|
153
|
+
.then((res) =>
|
|
154
|
+
res.length > 0 ? res[0] : null
|
|
155
|
+
) as Awaitable<AdapterUser | null>
|
|
153
156
|
},
|
|
154
157
|
async getUserByEmail(email: string) {
|
|
155
158
|
return client
|
|
156
159
|
.select()
|
|
157
160
|
.from(usersTable)
|
|
158
161
|
.where(eq(usersTable.email, email))
|
|
159
|
-
.then((res) =>
|
|
162
|
+
.then((res) =>
|
|
163
|
+
res.length > 0 ? res[0] : null
|
|
164
|
+
) as Awaitable<AdapterUser | null>
|
|
160
165
|
},
|
|
161
166
|
async createSession(data: {
|
|
162
167
|
sessionToken: string
|
|
@@ -178,7 +183,10 @@ export function PostgresDrizzleAdapter(
|
|
|
178
183
|
.from(sessionsTable)
|
|
179
184
|
.where(eq(sessionsTable.sessionToken, sessionToken))
|
|
180
185
|
.innerJoin(usersTable, eq(usersTable.id, sessionsTable.userId))
|
|
181
|
-
.then((res) => (res.length > 0 ? res[0] : null))
|
|
186
|
+
.then((res) => (res.length > 0 ? res[0] : null)) as Awaitable<{
|
|
187
|
+
session: AdapterSession
|
|
188
|
+
user: AdapterUser
|
|
189
|
+
} | null>
|
|
182
190
|
},
|
|
183
191
|
async updateUser(data: Partial<AdapterUser> & Pick<AdapterUser, "id">) {
|
|
184
192
|
if (!data.id) {
|
|
@@ -195,7 +203,7 @@ export function PostgresDrizzleAdapter(
|
|
|
195
203
|
throw new Error("No user found.")
|
|
196
204
|
}
|
|
197
205
|
|
|
198
|
-
return result
|
|
206
|
+
return result as Awaitable<AdapterUser>
|
|
199
207
|
},
|
|
200
208
|
async updateSession(
|
|
201
209
|
data: Partial<AdapterSession> & Pick<AdapterSession, "sessionToken">
|
|
@@ -228,7 +236,8 @@ export function PostgresDrizzleAdapter(
|
|
|
228
236
|
)
|
|
229
237
|
.then((res) => res[0])
|
|
230
238
|
|
|
231
|
-
|
|
239
|
+
const user = result?.user ?? null
|
|
240
|
+
return user as Awaitable<AdapterUser | null>
|
|
232
241
|
},
|
|
233
242
|
async deleteSession(sessionToken: string) {
|
|
234
243
|
await client
|
|
@@ -286,21 +295,21 @@ export function PostgresDrizzleAdapter(
|
|
|
286
295
|
.insert(authenticatorsTable)
|
|
287
296
|
.values(data)
|
|
288
297
|
.returning()
|
|
289
|
-
.then((res) => res[0] ?? null)
|
|
298
|
+
.then((res) => res[0] ?? null) as Awaitable<AdapterAuthenticator>
|
|
290
299
|
},
|
|
291
300
|
async getAuthenticator(credentialID: string) {
|
|
292
301
|
return client
|
|
293
302
|
.select()
|
|
294
303
|
.from(authenticatorsTable)
|
|
295
304
|
.where(eq(authenticatorsTable.credentialID, credentialID))
|
|
296
|
-
.then((res) => res[0] ?? null)
|
|
305
|
+
.then((res) => res[0] ?? null) as Awaitable<AdapterAuthenticator | null>
|
|
297
306
|
},
|
|
298
307
|
async listAuthenticatorsByUserId(userId: string) {
|
|
299
308
|
return client
|
|
300
309
|
.select()
|
|
301
310
|
.from(authenticatorsTable)
|
|
302
311
|
.where(eq(authenticatorsTable.userId, userId))
|
|
303
|
-
.then((res) => res)
|
|
312
|
+
.then((res) => res) as Awaitable<AdapterAuthenticator[]>
|
|
304
313
|
},
|
|
305
314
|
async updateAuthenticatorCounter(credentialID: string, newCounter: number) {
|
|
306
315
|
const authenticator = await client
|
|
@@ -312,7 +321,7 @@ export function PostgresDrizzleAdapter(
|
|
|
312
321
|
|
|
313
322
|
if (!authenticator) throw new Error("Authenticator not found.")
|
|
314
323
|
|
|
315
|
-
return authenticator
|
|
324
|
+
return authenticator as Awaitable<AdapterAuthenticator>
|
|
316
325
|
},
|
|
317
326
|
}
|
|
318
327
|
}
|
|
@@ -322,6 +331,7 @@ type DefaultPostgresColumn<
|
|
|
322
331
|
data: string | number | boolean | Date
|
|
323
332
|
dataType: "string" | "number" | "boolean" | "date"
|
|
324
333
|
notNull: boolean
|
|
334
|
+
isPrimaryKey?: boolean
|
|
325
335
|
columnType:
|
|
326
336
|
| "PgVarchar"
|
|
327
337
|
| "PgText"
|
|
@@ -332,6 +342,10 @@ type DefaultPostgresColumn<
|
|
|
332
342
|
},
|
|
333
343
|
> = PgColumn<{
|
|
334
344
|
name: string
|
|
345
|
+
isAutoincrement: boolean
|
|
346
|
+
isPrimaryKey: T["isPrimaryKey"] extends true ? true : false
|
|
347
|
+
hasRuntimeDefault: boolean
|
|
348
|
+
generated: GeneratedColumnConfig<T["data"]> | undefined
|
|
335
349
|
columnType: T["columnType"]
|
|
336
350
|
data: T["data"]
|
|
337
351
|
driverParam: string | number | boolean
|
|
@@ -347,6 +361,7 @@ export type DefaultPostgresUsersTable = PgTableWithColumns<{
|
|
|
347
361
|
columns: {
|
|
348
362
|
id: DefaultPostgresColumn<{
|
|
349
363
|
columnType: "PgVarchar" | "PgText" | "PgUUID"
|
|
364
|
+
isPrimaryKey: true
|
|
350
365
|
data: string
|
|
351
366
|
notNull: true
|
|
352
367
|
dataType: "string"
|
|
@@ -360,7 +375,7 @@ export type DefaultPostgresUsersTable = PgTableWithColumns<{
|
|
|
360
375
|
email: DefaultPostgresColumn<{
|
|
361
376
|
columnType: "PgVarchar" | "PgText"
|
|
362
377
|
data: string
|
|
363
|
-
notNull:
|
|
378
|
+
notNull: boolean
|
|
364
379
|
dataType: "string"
|
|
365
380
|
}>
|
|
366
381
|
emailVerified: DefaultPostgresColumn<{
|
|
@@ -460,6 +475,7 @@ export type DefaultPostgresSessionsTable = PgTableWithColumns<{
|
|
|
460
475
|
sessionToken: DefaultPostgresColumn<{
|
|
461
476
|
columnType: "PgVarchar" | "PgText"
|
|
462
477
|
data: string
|
|
478
|
+
isPrimaryKey: true
|
|
463
479
|
notNull: true
|
|
464
480
|
dataType: "string"
|
|
465
481
|
}>
|
package/src/lib/sqlite.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { and, eq, getTableColumns } from "drizzle-orm"
|
|
1
|
+
import { GeneratedColumnConfig, and, eq, getTableColumns } from "drizzle-orm"
|
|
2
2
|
import {
|
|
3
3
|
BaseSQLiteDatabase,
|
|
4
4
|
SQLiteColumn,
|
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
AdapterUser,
|
|
19
19
|
VerificationToken,
|
|
20
20
|
} from "@auth/core/adapters"
|
|
21
|
+
import { Awaitable } from "@auth/core/types"
|
|
21
22
|
|
|
22
23
|
export function defineTables(
|
|
23
24
|
schema: Partial<DefaultSQLiteSchema> = {}
|
|
@@ -29,7 +30,7 @@ export function defineTables(
|
|
|
29
30
|
.primaryKey()
|
|
30
31
|
.$defaultFn(() => crypto.randomUUID()),
|
|
31
32
|
name: text("name"),
|
|
32
|
-
email: text("email").
|
|
33
|
+
email: text("email").unique(),
|
|
33
34
|
emailVerified: integer("emailVerified", { mode: "timestamp_ms" }),
|
|
34
35
|
image: text("image"),
|
|
35
36
|
}) satisfies DefaultSQLiteUsersTable)
|
|
@@ -141,25 +142,27 @@ export function SQLiteDrizzleAdapter(
|
|
|
141
142
|
.insert(usersTable)
|
|
142
143
|
.values(hasDefaultId ? insertData : { ...insertData, id })
|
|
143
144
|
.returning()
|
|
144
|
-
.get()
|
|
145
|
+
.get() as Awaitable<AdapterUser>
|
|
145
146
|
},
|
|
146
147
|
async getUser(userId: string) {
|
|
147
|
-
const result =
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
148
|
+
const result =
|
|
149
|
+
(await client
|
|
150
|
+
.select()
|
|
151
|
+
.from(usersTable)
|
|
152
|
+
.where(eq(usersTable.id, userId))
|
|
153
|
+
.get()) ?? null
|
|
152
154
|
|
|
153
|
-
return result
|
|
155
|
+
return result as Awaitable<AdapterUser | null>
|
|
154
156
|
},
|
|
155
157
|
async getUserByEmail(email: string) {
|
|
156
|
-
const result =
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
const result =
|
|
159
|
+
(await client
|
|
160
|
+
.select()
|
|
161
|
+
.from(usersTable)
|
|
162
|
+
.where(eq(usersTable.email, email))
|
|
163
|
+
.get()) ?? null
|
|
161
164
|
|
|
162
|
-
return result
|
|
165
|
+
return result as Awaitable<AdapterUser | null>
|
|
163
166
|
},
|
|
164
167
|
async createSession(data: {
|
|
165
168
|
sessionToken: string
|
|
@@ -169,17 +172,21 @@ export function SQLiteDrizzleAdapter(
|
|
|
169
172
|
return client.insert(sessionsTable).values(data).returning().get()
|
|
170
173
|
},
|
|
171
174
|
async getSessionAndUser(sessionToken: string) {
|
|
172
|
-
const result =
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
175
|
+
const result =
|
|
176
|
+
(await client
|
|
177
|
+
.select({
|
|
178
|
+
session: sessionsTable,
|
|
179
|
+
user: usersTable,
|
|
180
|
+
})
|
|
181
|
+
.from(sessionsTable)
|
|
182
|
+
.where(eq(sessionsTable.sessionToken, sessionToken))
|
|
183
|
+
.innerJoin(usersTable, eq(usersTable.id, sessionsTable.userId))
|
|
184
|
+
.get()) ?? null
|
|
181
185
|
|
|
182
|
-
return result
|
|
186
|
+
return result as Awaitable<{
|
|
187
|
+
session: AdapterSession
|
|
188
|
+
user: AdapterUser
|
|
189
|
+
} | null>
|
|
183
190
|
},
|
|
184
191
|
async updateUser(data: Partial<AdapterUser> & Pick<AdapterUser, "id">) {
|
|
185
192
|
if (!data.id) {
|
|
@@ -197,7 +204,7 @@ export function SQLiteDrizzleAdapter(
|
|
|
197
204
|
throw new Error("User not found.")
|
|
198
205
|
}
|
|
199
206
|
|
|
200
|
-
return result
|
|
207
|
+
return result as Awaitable<AdapterUser>
|
|
201
208
|
},
|
|
202
209
|
async updateSession(
|
|
203
210
|
data: Partial<AdapterSession> & Pick<AdapterSession, "sessionToken">
|
|
@@ -232,7 +239,9 @@ export function SQLiteDrizzleAdapter(
|
|
|
232
239
|
)
|
|
233
240
|
.get()
|
|
234
241
|
|
|
235
|
-
|
|
242
|
+
const user = result?.user ?? null
|
|
243
|
+
|
|
244
|
+
return user as Awaitable<AdapterUser | null>
|
|
236
245
|
},
|
|
237
246
|
async deleteSession(sessionToken: string) {
|
|
238
247
|
await client
|
|
@@ -294,21 +303,21 @@ export function SQLiteDrizzleAdapter(
|
|
|
294
303
|
.insert(authenticatorsTable)
|
|
295
304
|
.values(data)
|
|
296
305
|
.returning()
|
|
297
|
-
.then((res) => res[0] ?? null)
|
|
306
|
+
.then((res) => res[0] ?? null) as Awaitable<AdapterAuthenticator>
|
|
298
307
|
},
|
|
299
308
|
async getAuthenticator(credentialID: string) {
|
|
300
309
|
return client
|
|
301
310
|
.select()
|
|
302
311
|
.from(authenticatorsTable)
|
|
303
312
|
.where(eq(authenticatorsTable.credentialID, credentialID))
|
|
304
|
-
.then((res) => res[0] ?? null)
|
|
313
|
+
.then((res) => res[0] ?? null) as Awaitable<AdapterAuthenticator | null>
|
|
305
314
|
},
|
|
306
315
|
async listAuthenticatorsByUserId(userId: string) {
|
|
307
316
|
return client
|
|
308
317
|
.select()
|
|
309
318
|
.from(authenticatorsTable)
|
|
310
319
|
.where(eq(authenticatorsTable.userId, userId))
|
|
311
|
-
.then((res) => res)
|
|
320
|
+
.then((res) => res) as Awaitable<AdapterAuthenticator[]>
|
|
312
321
|
},
|
|
313
322
|
async updateAuthenticatorCounter(credentialID: string, newCounter: number) {
|
|
314
323
|
const authenticator = await client
|
|
@@ -320,7 +329,7 @@ export function SQLiteDrizzleAdapter(
|
|
|
320
329
|
|
|
321
330
|
if (!authenticator) throw new Error("Authenticator not found.")
|
|
322
331
|
|
|
323
|
-
return authenticator
|
|
332
|
+
return authenticator as Awaitable<AdapterAuthenticator>
|
|
324
333
|
},
|
|
325
334
|
}
|
|
326
335
|
}
|
|
@@ -330,6 +339,7 @@ type DefaultSQLiteColumn<
|
|
|
330
339
|
data: string | boolean | number | Date
|
|
331
340
|
dataType: "string" | "boolean" | "number" | "date"
|
|
332
341
|
notNull: boolean
|
|
342
|
+
isPrimaryKey?: boolean
|
|
333
343
|
columnType:
|
|
334
344
|
| "SQLiteText"
|
|
335
345
|
| "SQLiteBoolean"
|
|
@@ -338,6 +348,10 @@ type DefaultSQLiteColumn<
|
|
|
338
348
|
},
|
|
339
349
|
> = SQLiteColumn<{
|
|
340
350
|
name: string
|
|
351
|
+
isAutoincrement: boolean
|
|
352
|
+
isPrimaryKey: T["isPrimaryKey"] extends true ? true : false
|
|
353
|
+
hasRuntimeDefault: boolean
|
|
354
|
+
generated: GeneratedColumnConfig<T["data"]> | undefined
|
|
341
355
|
columnType: T["columnType"]
|
|
342
356
|
data: T["data"]
|
|
343
357
|
driverParam: string | number | boolean
|
|
@@ -354,6 +368,7 @@ export type DefaultSQLiteUsersTable = SQLiteTableWithColumns<{
|
|
|
354
368
|
id: DefaultSQLiteColumn<{
|
|
355
369
|
columnType: "SQLiteText"
|
|
356
370
|
data: string
|
|
371
|
+
isPrimaryKey: true
|
|
357
372
|
notNull: true
|
|
358
373
|
dataType: "string"
|
|
359
374
|
}>
|
|
@@ -366,7 +381,7 @@ export type DefaultSQLiteUsersTable = SQLiteTableWithColumns<{
|
|
|
366
381
|
email: DefaultSQLiteColumn<{
|
|
367
382
|
columnType: "SQLiteText"
|
|
368
383
|
data: string
|
|
369
|
-
notNull:
|
|
384
|
+
notNull: boolean
|
|
370
385
|
dataType: "string"
|
|
371
386
|
}>
|
|
372
387
|
emailVerified: DefaultSQLiteColumn<{
|
|
@@ -466,6 +481,7 @@ export type DefaultSQLiteSessionsTable = SQLiteTableWithColumns<{
|
|
|
466
481
|
sessionToken: DefaultSQLiteColumn<{
|
|
467
482
|
columnType: "SQLiteText"
|
|
468
483
|
data: string
|
|
484
|
+
isPrimaryKey: true
|
|
469
485
|
notNull: true
|
|
470
486
|
dataType: "string"
|
|
471
487
|
}>
|
package/src/lib/utils.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
2
|
+
MySqlQueryResultHKT,
|
|
3
3
|
PreparedQueryHKTBase,
|
|
4
4
|
} from "drizzle-orm/mysql-core"
|
|
5
5
|
import { MySqlDatabase } from "drizzle-orm/mysql-core"
|
|
6
|
-
import
|
|
7
|
-
import { PgDatabase } from "drizzle-orm/pg-core"
|
|
6
|
+
import { PgDatabase, PgQueryResultHKT } from "drizzle-orm/pg-core"
|
|
8
7
|
import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core"
|
|
9
8
|
import { DefaultMySqlSchema } from "./mysql.js"
|
|
10
9
|
import { DefaultPostgresSchema } from "./pg.js"
|
|
11
10
|
import { DefaultSQLiteSchema } from "./sqlite.js"
|
|
12
11
|
|
|
13
|
-
type AnyPostgresDatabase = PgDatabase<
|
|
12
|
+
type AnyPostgresDatabase = PgDatabase<PgQueryResultHKT, any>
|
|
14
13
|
type AnyMySqlDatabase = MySqlDatabase<
|
|
15
|
-
|
|
14
|
+
MySqlQueryResultHKT,
|
|
16
15
|
PreparedQueryHKTBase,
|
|
17
16
|
any
|
|
18
17
|
>
|