@auth/drizzle-adapter 0.1.0 → 0.2.1

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/pg.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pg.d.ts","sourceRoot":"","sources":["../src/lib/pg.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,KAAK,EAAE,OAAO,EAAkB,MAAM,qBAAqB,CAAA;AAElE,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMhB,CAAA;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBpB,CAAA;AAED,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMnB,CAAA;AAEF,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAU9B,CAAA;AAED,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAoD,CAAA;AACvE,MAAM,MAAM,aAAa,GAAG,OAAO,MAAM,CAAA;AAEzC,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,GAChD,OAAO,CA6JT"}
1
+ {"version":3,"file":"pg.d.ts","sourceRoot":"","sources":["../src/lib/pg.ts"],"names":[],"mappings":"AACA,OAAO,EAML,SAAS,EACV,MAAM,qBAAqB,CAAA;AAE5B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,KAAK,EAAE,OAAO,EAAkB,MAAM,qBAAqB,CAAA;AAElE,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoD9C;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAA;AAE3D,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,EACjD,OAAO,uBAAmB,GACzB,OAAO,CAgKT"}
package/lib/pg.js CHANGED
@@ -1,45 +1,48 @@
1
1
  import { and, eq } from "drizzle-orm";
2
- import { timestamp, pgTable, text, primaryKey, integer, } from "drizzle-orm/pg-core";
3
- export const users = pgTable("users", {
4
- id: text("id").notNull().primaryKey(),
5
- name: text("name"),
6
- email: text("email").notNull(),
7
- emailVerified: timestamp("emailVerified", { mode: "date" }),
8
- image: text("image"),
9
- });
10
- export const accounts = pgTable("accounts", {
11
- userId: text("userId")
12
- .notNull()
13
- .references(() => users.id, { onDelete: "cascade" }),
14
- type: text("type").$type().notNull(),
15
- provider: text("provider").notNull(),
16
- providerAccountId: text("providerAccountId").notNull(),
17
- refresh_token: text("refresh_token"),
18
- access_token: text("access_token"),
19
- expires_at: integer("expires_at"),
20
- token_type: text("token_type"),
21
- scope: text("scope"),
22
- id_token: text("id_token"),
23
- session_state: text("session_state"),
24
- }, (account) => ({
25
- compoundKey: primaryKey(account.provider, account.providerAccountId),
26
- }));
27
- export const sessions = pgTable("sessions", {
28
- sessionToken: text("sessionToken").notNull().primaryKey(),
29
- userId: text("userId")
30
- .notNull()
31
- .references(() => users.id, { onDelete: "cascade" }),
32
- expires: timestamp("expires", { mode: "date" }).notNull(),
33
- });
34
- export const verificationTokens = pgTable("verificationToken", {
35
- identifier: text("identifier").notNull(),
36
- token: text("token").notNull(),
37
- expires: timestamp("expires", { mode: "date" }).notNull(),
38
- }, (vt) => ({
39
- compoundKey: primaryKey(vt.identifier, vt.token),
40
- }));
41
- export const schema = { users, accounts, sessions, verificationTokens };
42
- export function pgDrizzleAdapter(client) {
2
+ import { timestamp, pgTable as defaultPgTableFn, text, primaryKey, integer, } from "drizzle-orm/pg-core";
3
+ export function createTables(pgTable) {
4
+ const users = pgTable("users", {
5
+ id: text("id").notNull().primaryKey(),
6
+ name: text("name"),
7
+ email: text("email").notNull(),
8
+ emailVerified: timestamp("emailVerified", { mode: "date" }),
9
+ image: text("image"),
10
+ });
11
+ const accounts = pgTable("accounts", {
12
+ userId: text("userId")
13
+ .notNull()
14
+ .references(() => users.id, { onDelete: "cascade" }),
15
+ type: text("type").$type().notNull(),
16
+ provider: text("provider").notNull(),
17
+ providerAccountId: text("providerAccountId").notNull(),
18
+ refresh_token: text("refresh_token"),
19
+ access_token: text("access_token"),
20
+ expires_at: integer("expires_at"),
21
+ token_type: text("token_type"),
22
+ scope: text("scope"),
23
+ id_token: text("id_token"),
24
+ session_state: text("session_state"),
25
+ }, (account) => ({
26
+ compoundKey: primaryKey(account.provider, account.providerAccountId),
27
+ }));
28
+ const sessions = pgTable("sessions", {
29
+ sessionToken: text("sessionToken").notNull().primaryKey(),
30
+ userId: text("userId")
31
+ .notNull()
32
+ .references(() => users.id, { onDelete: "cascade" }),
33
+ expires: timestamp("expires", { mode: "date" }).notNull(),
34
+ });
35
+ const verificationTokens = pgTable("verificationToken", {
36
+ identifier: text("identifier").notNull(),
37
+ token: text("token").notNull(),
38
+ expires: timestamp("expires", { mode: "date" }).notNull(),
39
+ }, (vt) => ({
40
+ compoundKey: primaryKey(vt.identifier, vt.token),
41
+ }));
42
+ return { users, accounts, sessions, verificationTokens };
43
+ }
44
+ export function pgDrizzleAdapter(client, tableFn = defaultPgTableFn) {
45
+ const { users, accounts, sessions, verificationTokens } = createTables(tableFn);
43
46
  return {
44
47
  async createUser(data) {
45
48
  return await client
package/lib/sqlite.d.ts CHANGED
@@ -1,224 +1,6 @@
1
- import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core";
1
+ import { BaseSQLiteDatabase, SQLiteTableFn } from "drizzle-orm/sqlite-core";
2
2
  import type { Adapter } from "@auth/core/adapters";
3
- export declare const users: import("drizzle-orm/db.d-b5fdf746").ag<{
4
- name: "users";
5
- schema: undefined;
6
- columns: {
7
- id: import("drizzle-orm/sqlite-core").SQLiteText<{
8
- tableName: "users";
9
- enumValues: [string, ...string[]];
10
- name: "id";
11
- data: string;
12
- driverParam: string;
13
- hasDefault: false;
14
- notNull: true;
15
- }>;
16
- name: import("drizzle-orm/sqlite-core").SQLiteText<{
17
- tableName: "users";
18
- name: "name";
19
- data: string;
20
- driverParam: string;
21
- enumValues: [string, ...string[]];
22
- notNull: false;
23
- hasDefault: false;
24
- }>;
25
- email: import("drizzle-orm/sqlite-core").SQLiteText<{
26
- tableName: "users";
27
- enumValues: [string, ...string[]];
28
- name: "email";
29
- data: string;
30
- driverParam: string;
31
- hasDefault: false;
32
- notNull: true;
33
- }>;
34
- emailVerified: import("drizzle-orm/sqlite-core").SQLiteTimestamp<{
35
- tableName: "users";
36
- name: "emailVerified";
37
- data: Date;
38
- driverParam: number;
39
- notNull: false;
40
- hasDefault: false;
41
- }>;
42
- image: import("drizzle-orm/sqlite-core").SQLiteText<{
43
- tableName: "users";
44
- name: "image";
45
- data: string;
46
- driverParam: string;
47
- enumValues: [string, ...string[]];
48
- notNull: false;
49
- hasDefault: false;
50
- }>;
51
- };
52
- }>;
53
- export declare const accounts: import("drizzle-orm/db.d-b5fdf746").ag<{
54
- name: "accounts";
55
- schema: undefined;
56
- columns: {
57
- userId: import("drizzle-orm/sqlite-core").SQLiteText<{
58
- tableName: "accounts";
59
- enumValues: [string, ...string[]];
60
- name: "userId";
61
- data: string;
62
- driverParam: string;
63
- hasDefault: false;
64
- notNull: true;
65
- }>;
66
- type: import("drizzle-orm/sqlite-core").SQLiteText<{
67
- tableName: "accounts";
68
- enumValues: [string, ...string[]];
69
- name: "type";
70
- data: "email" | "oidc" | "oauth";
71
- driverParam: string;
72
- hasDefault: false;
73
- notNull: true;
74
- }>;
75
- provider: import("drizzle-orm/sqlite-core").SQLiteText<{
76
- tableName: "accounts";
77
- enumValues: [string, ...string[]];
78
- name: "provider";
79
- data: string;
80
- driverParam: string;
81
- hasDefault: false;
82
- notNull: true;
83
- }>;
84
- providerAccountId: import("drizzle-orm/sqlite-core").SQLiteText<{
85
- tableName: "accounts";
86
- enumValues: [string, ...string[]];
87
- name: "providerAccountId";
88
- data: string;
89
- driverParam: string;
90
- hasDefault: false;
91
- notNull: true;
92
- }>;
93
- refresh_token: import("drizzle-orm/sqlite-core").SQLiteText<{
94
- tableName: "accounts";
95
- name: "refresh_token";
96
- data: string;
97
- driverParam: string;
98
- enumValues: [string, ...string[]];
99
- notNull: false;
100
- hasDefault: false;
101
- }>;
102
- access_token: import("drizzle-orm/sqlite-core").SQLiteText<{
103
- tableName: "accounts";
104
- name: "access_token";
105
- data: string;
106
- driverParam: string;
107
- enumValues: [string, ...string[]];
108
- notNull: false;
109
- hasDefault: false;
110
- }>;
111
- expires_at: import("drizzle-orm/sqlite-core").SQLiteInteger<{
112
- tableName: "accounts";
113
- name: "expires_at";
114
- data: number;
115
- driverParam: number;
116
- notNull: false;
117
- hasDefault: false;
118
- }>;
119
- token_type: import("drizzle-orm/sqlite-core").SQLiteText<{
120
- tableName: "accounts";
121
- name: "token_type";
122
- data: string;
123
- driverParam: string;
124
- enumValues: [string, ...string[]];
125
- notNull: false;
126
- hasDefault: false;
127
- }>;
128
- scope: import("drizzle-orm/sqlite-core").SQLiteText<{
129
- tableName: "accounts";
130
- name: "scope";
131
- data: string;
132
- driverParam: string;
133
- enumValues: [string, ...string[]];
134
- notNull: false;
135
- hasDefault: false;
136
- }>;
137
- id_token: import("drizzle-orm/sqlite-core").SQLiteText<{
138
- tableName: "accounts";
139
- name: "id_token";
140
- data: string;
141
- driverParam: string;
142
- enumValues: [string, ...string[]];
143
- notNull: false;
144
- hasDefault: false;
145
- }>;
146
- session_state: import("drizzle-orm/sqlite-core").SQLiteText<{
147
- tableName: "accounts";
148
- name: "session_state";
149
- data: string;
150
- driverParam: string;
151
- enumValues: [string, ...string[]];
152
- notNull: false;
153
- hasDefault: false;
154
- }>;
155
- };
156
- }>;
157
- export declare const sessions: import("drizzle-orm/db.d-b5fdf746").ag<{
158
- name: "sessions";
159
- schema: undefined;
160
- columns: {
161
- sessionToken: import("drizzle-orm/sqlite-core").SQLiteText<{
162
- tableName: "sessions";
163
- enumValues: [string, ...string[]];
164
- name: "sessionToken";
165
- data: string;
166
- driverParam: string;
167
- hasDefault: false;
168
- notNull: true;
169
- }>;
170
- userId: import("drizzle-orm/sqlite-core").SQLiteText<{
171
- tableName: "sessions";
172
- enumValues: [string, ...string[]];
173
- name: "userId";
174
- data: string;
175
- driverParam: string;
176
- hasDefault: false;
177
- notNull: true;
178
- }>;
179
- expires: import("drizzle-orm/sqlite-core").SQLiteTimestamp<{
180
- tableName: "sessions";
181
- name: "expires";
182
- data: Date;
183
- driverParam: number;
184
- hasDefault: false;
185
- notNull: true;
186
- }>;
187
- };
188
- }>;
189
- export declare const verificationTokens: import("drizzle-orm/db.d-b5fdf746").ag<{
190
- name: "verificationToken";
191
- schema: undefined;
192
- columns: {
193
- identifier: import("drizzle-orm/sqlite-core").SQLiteText<{
194
- tableName: "verificationToken";
195
- enumValues: [string, ...string[]];
196
- name: "identifier";
197
- data: string;
198
- driverParam: string;
199
- hasDefault: false;
200
- notNull: true;
201
- }>;
202
- token: import("drizzle-orm/sqlite-core").SQLiteText<{
203
- tableName: "verificationToken";
204
- enumValues: [string, ...string[]];
205
- name: "token";
206
- data: string;
207
- driverParam: string;
208
- hasDefault: false;
209
- notNull: true;
210
- }>;
211
- expires: import("drizzle-orm/sqlite-core").SQLiteTimestamp<{
212
- tableName: "verificationToken";
213
- name: "expires";
214
- data: Date;
215
- driverParam: number;
216
- hasDefault: false;
217
- notNull: true;
218
- }>;
219
- };
220
- }>;
221
- export declare const schema: {
3
+ export declare function createTables(sqliteTable: SQLiteTableFn): {
222
4
  users: import("drizzle-orm/db.d-b5fdf746").ag<{
223
5
  name: "users";
224
6
  schema: undefined;
@@ -438,6 +220,6 @@ export declare const schema: {
438
220
  };
439
221
  }>;
440
222
  };
441
- export type DefaultSchema = typeof schema;
442
- export declare function SQLiteDrizzleAdapter(client: BaseSQLiteDatabase<any, any>): Adapter;
223
+ export type DefaultSchema = ReturnType<typeof createTables>;
224
+ export declare function SQLiteDrizzleAdapter(client: BaseSQLiteDatabase<any, any>, tableFn?: SQLiteTableFn<undefined>): Adapter;
443
225
  //# sourceMappingURL=sqlite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../src/lib/sqlite.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,kBAAkB,EACnB,MAAM,yBAAyB,CAAA;AAEhC,OAAO,KAAK,EAAE,OAAO,EAAkB,MAAM,qBAAqB,CAAA;AAElE,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMhB,CAAA;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBpB,CAAA;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GAAG,EAAE,GAAG,CAAC,EACpC,OAAO,2BAAuB,GAC7B,OAAO,CA2IT"}
package/lib/sqlite.js CHANGED
@@ -1,45 +1,48 @@
1
1
  import { eq, and } from "drizzle-orm";
2
- import { integer, sqliteTable, text, primaryKey, } from "drizzle-orm/sqlite-core";
3
- export const users = sqliteTable("users", {
4
- id: text("id").notNull().primaryKey(),
5
- name: text("name"),
6
- email: text("email").notNull(),
7
- emailVerified: integer("emailVerified", { mode: "timestamp_ms" }),
8
- image: text("image"),
9
- });
10
- export const accounts = sqliteTable("accounts", {
11
- userId: text("userId")
12
- .notNull()
13
- .references(() => users.id, { onDelete: "cascade" }),
14
- type: text("type").$type().notNull(),
15
- provider: text("provider").notNull(),
16
- providerAccountId: text("providerAccountId").notNull(),
17
- refresh_token: text("refresh_token"),
18
- access_token: text("access_token"),
19
- expires_at: integer("expires_at"),
20
- token_type: text("token_type"),
21
- scope: text("scope"),
22
- id_token: text("id_token"),
23
- session_state: text("session_state"),
24
- }, (account) => ({
25
- compoundKey: primaryKey(account.provider, account.providerAccountId),
26
- }));
27
- export const sessions = sqliteTable("sessions", {
28
- sessionToken: text("sessionToken").notNull().primaryKey(),
29
- userId: text("userId")
30
- .notNull()
31
- .references(() => users.id, { onDelete: "cascade" }),
32
- expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
33
- });
34
- export const verificationTokens = sqliteTable("verificationToken", {
35
- identifier: text("identifier").notNull(),
36
- token: text("token").notNull(),
37
- expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
38
- }, (vt) => ({
39
- compoundKey: primaryKey(vt.identifier, vt.token),
40
- }));
41
- export const schema = { users, accounts, sessions, verificationTokens };
42
- export function SQLiteDrizzleAdapter(client) {
2
+ import { integer, sqliteTable as defaultSqliteTableFn, text, primaryKey, } from "drizzle-orm/sqlite-core";
3
+ export function createTables(sqliteTable) {
4
+ const users = sqliteTable("users", {
5
+ id: text("id").notNull().primaryKey(),
6
+ name: text("name"),
7
+ email: text("email").notNull(),
8
+ emailVerified: integer("emailVerified", { mode: "timestamp_ms" }),
9
+ image: text("image"),
10
+ });
11
+ const accounts = sqliteTable("accounts", {
12
+ userId: text("userId")
13
+ .notNull()
14
+ .references(() => users.id, { onDelete: "cascade" }),
15
+ type: text("type").$type().notNull(),
16
+ provider: text("provider").notNull(),
17
+ providerAccountId: text("providerAccountId").notNull(),
18
+ refresh_token: text("refresh_token"),
19
+ access_token: text("access_token"),
20
+ expires_at: integer("expires_at"),
21
+ token_type: text("token_type"),
22
+ scope: text("scope"),
23
+ id_token: text("id_token"),
24
+ session_state: text("session_state"),
25
+ }, (account) => ({
26
+ compoundKey: primaryKey(account.provider, account.providerAccountId),
27
+ }));
28
+ const sessions = sqliteTable("sessions", {
29
+ sessionToken: text("sessionToken").notNull().primaryKey(),
30
+ userId: text("userId")
31
+ .notNull()
32
+ .references(() => users.id, { onDelete: "cascade" }),
33
+ expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
34
+ });
35
+ const verificationTokens = sqliteTable("verificationToken", {
36
+ identifier: text("identifier").notNull(),
37
+ token: text("token").notNull(),
38
+ expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
39
+ }, (vt) => ({
40
+ compoundKey: primaryKey(vt.identifier, vt.token),
41
+ }));
42
+ return { users, accounts, sessions, verificationTokens };
43
+ }
44
+ export function SQLiteDrizzleAdapter(client, tableFn = defaultSqliteTableFn) {
45
+ const { users, accounts, sessions, verificationTokens } = createTables(tableFn);
43
46
  return {
44
47
  createUser(data) {
45
48
  return client
package/lib/utils.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { MySqlDatabase } from "drizzle-orm/mysql-core";
2
2
  import { PgDatabase } from "drizzle-orm/pg-core";
3
3
  import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core";
4
- import type { AnyMySqlTable } from "drizzle-orm/mysql-core";
5
- import type { AnyPgTable } from "drizzle-orm/pg-core";
6
- import type { AnySQLiteTable } from "drizzle-orm/sqlite-core";
4
+ import type { AnyMySqlTable, MySqlTableFn } from "drizzle-orm/mysql-core";
5
+ import type { AnyPgTable, PgTableFn } from "drizzle-orm/pg-core";
6
+ import type { AnySQLiteTable, SQLiteTableFn } from "drizzle-orm/sqlite-core";
7
7
  import type { DefaultSchema as PgSchema } from "./pg.js";
8
8
  import type { DefaultSchema as MySqlSchema } from "./mysql.js";
9
9
  import type { DefaultSchema as SQLiteSchema } from "./sqlite.js";
@@ -17,6 +17,7 @@ export interface MinimumSchema {
17
17
  }
18
18
  export type SqlFlavorOptions = AnyMySqlDatabase | AnyPgDatabase | AnySQLiteDatabase;
19
19
  export type ClientFlavors<Flavor> = Flavor extends AnyMySqlDatabase ? MinimumSchema["mysql"] : Flavor extends AnyPgDatabase ? MinimumSchema["pg"] : Flavor extends AnySQLiteDatabase ? MinimumSchema["sqlite"] : never;
20
+ export type TableFn<Flavor> = Flavor extends AnyMySqlDatabase ? MySqlTableFn : Flavor extends AnyPgDatabase ? PgTableFn : Flavor extends AnySQLiteDatabase ? SQLiteTableFn : AnySQLiteTable;
20
21
  export declare function isMySqlDatabase(db: any): db is MySqlDatabase<any, any, any, any>;
21
22
  export declare function isPgDatabase(db: any): db is PgDatabase<any, any, any>;
22
23
  export declare function isSQLiteDatabase(db: any): db is AnySQLiteDatabase;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAAE,aAAa,I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,gBAAgB,GACxB,gBAAgB,GAChB,aAAa,GACb,iBAAiB,CAAA;AAErB,MAAM,MAAM,aAAa,CAAC,MAAM,IAAI,MAAM,SAAS,gBAAgB,GAC/D,aAAa,CAAC,OAAO,CAAC,GACtB,MAAM,SAAS,aAAa,GAC5B,aAAa,CAAC,IAAI,CAAC,GACnB,MAAM,SAAS,iBAAiB,GAChC,aAAa,CAAC,QAAQ,CAAC,GACvB,KAAK,CAAA;AAET,MAAM,MAAM,OAAO,CAAC,MAAM,IAAI,MAAM,SAAS,gBAAgB,GACzD,YAAY,GACZ,MAAM,SAAS,aAAa,GAC5B,SAAS,GACT,MAAM,SAAS,iBAAiB,GAChC,aAAa,GACb,cAAc,CAAA;AAElB,wBAAgB,eAAe,CAC7B,EAAE,EAAE,GAAG,GACN,EAAE,IAAI,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAEzC;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,GAAG,GAAG,EAAE,IAAI,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAErE;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,GAAG,GAAG,EAAE,IAAI,iBAAiB,CAEjE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auth/drizzle-adapter",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Drizzle adapter for Auth.js.",
5
5
  "homepage": "https://authjs.dev",
6
6
  "repository": "https://github.com/nextauthjs/next-auth",
package/src/index.ts CHANGED
@@ -16,6 +16,9 @@
16
16
  * @module @auth/drizzle-adapter
17
17
  */
18
18
 
19
+ import { MySqlTableFn } from "drizzle-orm/mysql-core/index.js"
20
+ import { PgTableFn } from "drizzle-orm/pg-core/index.js"
21
+ import { SQLiteTableFn } from "drizzle-orm/sqlite-core/index.js"
19
22
  import { mySqlDrizzleAdapter } from "./lib/mysql.js"
20
23
  import { pgDrizzleAdapter } from "./lib/pg.js"
21
24
  import { SQLiteDrizzleAdapter } from "./lib/sqlite.js"
@@ -24,12 +27,13 @@ import {
24
27
  isPgDatabase,
25
28
  isSQLiteDatabase,
26
29
  SqlFlavorOptions,
30
+ TableFn,
27
31
  } from "./lib/utils.js"
28
32
 
29
33
  import type { Adapter } from "@auth/core/adapters"
30
34
 
31
35
  /**
32
- * Add the adapter to your `app/api/[...nextauth]/route.js` next-auth configuration object.
36
+ * Add the adapter to your `pages/api/[...nextauth].ts` next-auth configuration object.
33
37
  *
34
38
  * ```ts title="pages/api/auth/[...nextauth].ts"
35
39
  * import NextAuth from "next-auth"
@@ -47,6 +51,10 @@ import type { Adapter } from "@auth/core/adapters"
47
51
  * ],
48
52
  * })
49
53
  * ```
54
+ *
55
+ * :::info
56
+ * If you're using multi-project schemas, you can pass your table function as a second argument
57
+ * :::
50
58
  *
51
59
  * ## Setup
52
60
  *
@@ -249,19 +257,20 @@ import type { Adapter } from "@auth/core/adapters"
249
257
  *
250
258
  **/
251
259
  export function DrizzleAdapter<SqlFlavor extends SqlFlavorOptions>(
252
- db: SqlFlavor
260
+ db: SqlFlavor,
261
+ table?: TableFn<SqlFlavor>
253
262
  ): Adapter {
254
263
  if (isMySqlDatabase(db)) {
255
264
  // We need to cast to unknown since the type overlaps (PScale is MySQL based)
256
- return mySqlDrizzleAdapter(db)
265
+ return mySqlDrizzleAdapter(db, table as MySqlTableFn)
257
266
  }
258
267
 
259
268
  if (isPgDatabase(db)) {
260
- return pgDrizzleAdapter(db)
269
+ return pgDrizzleAdapter(db, table as PgTableFn)
261
270
  }
262
271
 
263
272
  if (isSQLiteDatabase(db)) {
264
- return SQLiteDrizzleAdapter(db)
273
+ return SQLiteDrizzleAdapter(db, table as SQLiteTableFn)
265
274
  }
266
275
 
267
276
  throw new Error("Unsupported database type in Auth.js Drizzle adapter.")