@auth/drizzle-adapter 0.8.2 → 1.0.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/README.md +1 -1
- package/index.d.ts +59 -32
- package/index.d.ts.map +1 -1
- package/index.js +64 -37
- package/lib/mysql.d.ts +317 -296
- package/lib/mysql.d.ts.map +1 -1
- package/lib/mysql.js +134 -142
- package/lib/pg.d.ts +317 -296
- package/lib/pg.d.ts.map +1 -1
- package/lib/pg.js +128 -123
- package/lib/sqlite.d.ts +317 -296
- package/lib/sqlite.d.ts.map +1 -1
- package/lib/sqlite.js +109 -108
- package/lib/utils.d.ts +10 -21
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +1 -7
- package/package.json +7 -7
- package/src/index.ts +83 -41
- package/src/lib/mysql.ts +209 -190
- package/src/lib/pg.ts +194 -155
- package/src/lib/sqlite.ts +175 -133
- package/src/lib/utils.ts +22 -41
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<br/>
|
|
3
3
|
<a href="https://authjs.dev" target="_blank">
|
|
4
|
-
<img height="64px" src="https://authjs.dev/img/logo
|
|
4
|
+
<img height="64px" src="https://authjs.dev/img/logo-sm.png" />
|
|
5
5
|
</a>
|
|
6
6
|
<a href="https://github.com/drizzle-team/drizzle-orm" target="_blank">
|
|
7
7
|
<img height="64px" src="https://authjs.dev/img/adapters/drizzle-orm.png"/>
|
package/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: 16}}>
|
|
3
3
|
* <p style={{fontWeight: "normal"}}>Official <a href="https://orm.drizzle.team">Drizzle ORM</a> adapter for Auth.js / NextAuth.js.</p>
|
|
4
4
|
* <a href="https://orm.drizzle.team">
|
|
5
|
-
* <img style={{display: "block"}} src="/img/adapters/drizzle
|
|
5
|
+
* <img style={{display: "block"}} src="/img/adapters/drizzle.svg" width="38" />
|
|
6
6
|
* </a>
|
|
7
7
|
* </div>
|
|
8
8
|
*
|
|
@@ -15,32 +15,46 @@
|
|
|
15
15
|
*
|
|
16
16
|
* @module @auth/drizzle-adapter
|
|
17
17
|
*/
|
|
18
|
-
import {
|
|
18
|
+
import { DefaultSchema, SqlFlavorOptions } from "./lib/utils.js";
|
|
19
19
|
import type { Adapter } from "@auth/core/adapters";
|
|
20
|
+
export { postgresUsersTable, postgresAccountsTable, postgresSessionsTable, postgresVerificationTokensTable, } from "./lib/pg.js";
|
|
21
|
+
export { sqliteUsersTable, sqliteAccountsTable, sqliteSessionsTable, sqliteVerificationTokensTable, } from "./lib/sqlite.js";
|
|
22
|
+
export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificationTokensTable, } from "./lib/mysql.js";
|
|
20
23
|
/**
|
|
21
|
-
* Add
|
|
24
|
+
* Add this adapter to your `auth.ts` Auth.js configuration object:
|
|
22
25
|
*
|
|
23
|
-
* ```ts title="
|
|
26
|
+
* ```ts title="auth.ts"
|
|
24
27
|
* import NextAuth from "next-auth"
|
|
25
|
-
* import
|
|
28
|
+
* import Google from "next-auth/providers/google"
|
|
26
29
|
* import { DrizzleAdapter } from "@auth/drizzle-adapter"
|
|
27
30
|
* import { db } from "./schema"
|
|
28
31
|
*
|
|
29
|
-
* export
|
|
32
|
+
* export const { handlers, auth } = NextAuth({
|
|
30
33
|
* adapter: DrizzleAdapter(db),
|
|
31
34
|
* providers: [
|
|
32
|
-
*
|
|
33
|
-
* clientId: process.env.GOOGLE_CLIENT_ID,
|
|
34
|
-
* clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
|
35
|
-
* }),
|
|
35
|
+
* Google,
|
|
36
36
|
* ],
|
|
37
37
|
* })
|
|
38
38
|
* ```
|
|
39
39
|
*
|
|
40
40
|
* :::info
|
|
41
|
-
* If you
|
|
41
|
+
* If you want to use your own tables, you can pass them as a second argument
|
|
42
42
|
* :::
|
|
43
43
|
*
|
|
44
|
+
* ```ts title="auth.ts"
|
|
45
|
+
* import NextAuth from "next-auth"
|
|
46
|
+
* import Google from "next-auth/providers/google"
|
|
47
|
+
* import { DrizzleAdapter } from "@auth/drizzle-adapter"
|
|
48
|
+
* import { db, accounts, sessions, users, verificationTokens } from "./schema"
|
|
49
|
+
*
|
|
50
|
+
* export const { handlers, auth } = NextAuth({
|
|
51
|
+
* adapter: DrizzleAdapter(db, { usersTable: users, accountsTable: accounts, sessionsTable: sessions, verificationTokensTable: verificationTokens }),
|
|
52
|
+
* providers: [
|
|
53
|
+
* Google,
|
|
54
|
+
* ],
|
|
55
|
+
* })
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
44
58
|
* ## Setup
|
|
45
59
|
*
|
|
46
60
|
* First, create a schema that includes [the minimum requirements for a `next-auth` adapter](/reference/core/adapters#models). You can select your favorite SQL flavor below and copy it.
|
|
@@ -61,11 +75,12 @@ import type { Adapter } from "@auth/core/adapters";
|
|
|
61
75
|
* integer
|
|
62
76
|
* } from "drizzle-orm/pg-core"
|
|
63
77
|
* import type { AdapterAccount } from '@auth/core/adapters'
|
|
78
|
+
* import { randomUUID } from "crypto"
|
|
64
79
|
*
|
|
65
80
|
* export const users = pgTable("user", {
|
|
66
|
-
* id: text("id").
|
|
81
|
+
* id: text("id").primaryKey().$defaultFn(() => randomUUID()),
|
|
67
82
|
* name: text("name"),
|
|
68
|
-
* email: text("email").notNull(),
|
|
83
|
+
* email: text("email").notNull().unique(),
|
|
69
84
|
* emailVerified: timestamp("emailVerified", { mode: "date" }),
|
|
70
85
|
* image: text("image"),
|
|
71
86
|
* })
|
|
@@ -76,7 +91,7 @@ import type { Adapter } from "@auth/core/adapters";
|
|
|
76
91
|
* userId: text("userId")
|
|
77
92
|
* .notNull()
|
|
78
93
|
* .references(() => users.id, { onDelete: "cascade" }),
|
|
79
|
-
* type: text("type")
|
|
94
|
+
* type: text("type").notNull(),
|
|
80
95
|
* provider: text("provider").notNull(),
|
|
81
96
|
* providerAccountId: text("providerAccountId").notNull(),
|
|
82
97
|
* refresh_token: text("refresh_token"),
|
|
@@ -88,23 +103,27 @@ import type { Adapter } from "@auth/core/adapters";
|
|
|
88
103
|
* session_state: text("session_state"),
|
|
89
104
|
* },
|
|
90
105
|
* (account) => ({
|
|
106
|
+
* userIdIdx: index().on(account.userId),
|
|
91
107
|
* compoundKey: primaryKey({ columns: [account.provider, account.providerAccountId] }),
|
|
92
108
|
* })
|
|
93
109
|
* )
|
|
94
110
|
*
|
|
95
111
|
* export const sessions = pgTable("session", {
|
|
96
|
-
*
|
|
112
|
+
* id: text("id").primaryKey().$defaultFn(() => randomUUID()),
|
|
113
|
+
* sessionToken: text("sessionToken").notNull().unique(),
|
|
97
114
|
* userId: text("userId")
|
|
98
115
|
* .notNull()
|
|
99
116
|
* .references(() => users.id, { onDelete: "cascade" }),
|
|
100
117
|
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
101
|
-
* })
|
|
118
|
+
* }, (session) => ({
|
|
119
|
+
* userIdIdx: index().on(session.userId)
|
|
120
|
+
* }))
|
|
102
121
|
*
|
|
103
122
|
* export const verificationTokens = pgTable(
|
|
104
123
|
* "verificationToken",
|
|
105
124
|
* {
|
|
106
125
|
* identifier: text("identifier").notNull(),
|
|
107
|
-
* token: text("token").notNull(),
|
|
126
|
+
* token: text("token").notNull().unique(),
|
|
108
127
|
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
109
128
|
* },
|
|
110
129
|
* (vt) => ({
|
|
@@ -126,10 +145,10 @@ import type { Adapter } from "@auth/core/adapters";
|
|
|
126
145
|
* import type { AdapterAccount } from "@auth/core/adapters"
|
|
127
146
|
*
|
|
128
147
|
* export const users = mysqlTable("user", {
|
|
129
|
-
* id: varchar("id", { length: 255 }).
|
|
148
|
+
* id: varchar("id", { length: 255 }).primaryKey().$defaultFn(() => randomUUID()),
|
|
130
149
|
* name: varchar("name", { length: 255 }),
|
|
131
|
-
* email: varchar("email", { length: 255 }).notNull(),
|
|
132
|
-
*
|
|
150
|
+
* email: varchar("email", { length: 255 }).notNull().unique(),
|
|
151
|
+
* emailVerified: timestamp("emailVerified", { mode: "date", fsp: 3 }),
|
|
133
152
|
* image: varchar("image", { length: 255 }),
|
|
134
153
|
* })
|
|
135
154
|
*
|
|
@@ -139,8 +158,8 @@ import type { Adapter } from "@auth/core/adapters";
|
|
|
139
158
|
* userId: varchar("userId", { length: 255 })
|
|
140
159
|
* .notNull()
|
|
141
160
|
* .references(() => users.id, { onDelete: "cascade" }),
|
|
142
|
-
* type: varchar("type", { length: 255 })
|
|
143
|
-
*
|
|
161
|
+
* type: varchar("type", { length: 255 }).notNull(),
|
|
162
|
+
* provider: varchar("provider", { length: 255 }).notNull(),
|
|
144
163
|
* providerAccountId: varchar("providerAccountId", { length: 255 }).notNull(),
|
|
145
164
|
* refresh_token: varchar("refresh_token", { length: 255 }),
|
|
146
165
|
* access_token: varchar("access_token", { length: 255 }),
|
|
@@ -154,22 +173,26 @@ import type { Adapter } from "@auth/core/adapters";
|
|
|
154
173
|
* compoundKey: primaryKey({
|
|
155
174
|
columns: [account.provider, account.providerAccountId],
|
|
156
175
|
}),
|
|
176
|
+
userIdIdx: index('Account_userId_index').on(account.userId)
|
|
157
177
|
* })
|
|
158
178
|
* )
|
|
159
179
|
*
|
|
160
180
|
* export const sessions = mysqlTable("session", {
|
|
161
|
-
*
|
|
181
|
+
* id: varchar("id", { length: 255 }).primaryKey().$defaultFn(() => randomUUID()),
|
|
182
|
+
* sessionToken: varchar("sessionToken", { length: 255 }).notNull().unique(),
|
|
162
183
|
* userId: varchar("userId", { length: 255 })
|
|
163
184
|
* .notNull()
|
|
164
185
|
* .references(() => users.id, { onDelete: "cascade" }),
|
|
165
186
|
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
166
|
-
* })
|
|
187
|
+
* }, (session) => ({
|
|
188
|
+
* userIdIdx: index('Session_userId_index').on(session.userId)
|
|
189
|
+
* }))
|
|
167
190
|
*
|
|
168
191
|
* export const verificationTokens = mysqlTable(
|
|
169
192
|
* "verificationToken",
|
|
170
193
|
* {
|
|
171
194
|
* identifier: varchar("identifier", { length: 255 }).notNull(),
|
|
172
|
-
* token: varchar("token", { length: 255 }).notNull(),
|
|
195
|
+
* token: varchar("token", { length: 255 }).notNull().unique(),
|
|
173
196
|
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
174
197
|
* },
|
|
175
198
|
* (vt) => ({
|
|
@@ -185,9 +208,9 @@ import type { Adapter } from "@auth/core/adapters";
|
|
|
185
208
|
* import type { AdapterAccount } from "@auth/core/adapters"
|
|
186
209
|
*
|
|
187
210
|
* export const users = sqliteTable("user", {
|
|
188
|
-
* id: text("id").
|
|
211
|
+
* id: text("id").primaryKey().$defaultFn(() => randomUUID()),
|
|
189
212
|
* name: text("name"),
|
|
190
|
-
* email: text("email").notNull(),
|
|
213
|
+
* email: text("email").notNull().unique(),
|
|
191
214
|
* emailVerified: integer("emailVerified", { mode: "timestamp_ms" }),
|
|
192
215
|
* image: text("image"),
|
|
193
216
|
* })
|
|
@@ -198,7 +221,7 @@ import type { Adapter } from "@auth/core/adapters";
|
|
|
198
221
|
* userId: text("userId")
|
|
199
222
|
* .notNull()
|
|
200
223
|
* .references(() => users.id, { onDelete: "cascade" }),
|
|
201
|
-
* type: text("type")
|
|
224
|
+
* type: text("type").notNull(),
|
|
202
225
|
* provider: text("provider").notNull(),
|
|
203
226
|
* providerAccountId: text("providerAccountId").notNull(),
|
|
204
227
|
* refresh_token: text("refresh_token"),
|
|
@@ -213,22 +236,26 @@ import type { Adapter } from "@auth/core/adapters";
|
|
|
213
236
|
* compoundKey: primaryKey({
|
|
214
237
|
columns: [account.provider, account.providerAccountId],
|
|
215
238
|
}),
|
|
239
|
+
userIdIdx: index('Account_userId_index').on(account.userId)
|
|
216
240
|
* })
|
|
217
241
|
* )
|
|
218
242
|
*
|
|
219
243
|
* export const sessions = sqliteTable("session", {
|
|
220
|
-
*
|
|
244
|
+
* id: text("id").primaryKey().$defaultFn(() => randomUUID())
|
|
245
|
+
* sessionToken: text("sessionToken").notNull().unique(),
|
|
221
246
|
* userId: text("userId")
|
|
222
247
|
* .notNull()
|
|
223
248
|
* .references(() => users.id, { onDelete: "cascade" }),
|
|
224
249
|
* expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
|
225
|
-
* })
|
|
250
|
+
* }, (table) => ({
|
|
251
|
+
* userIdIdx: index('Session_userId_index').on(table.userId)
|
|
252
|
+
* }))
|
|
226
253
|
*
|
|
227
254
|
* export const verificationTokens = sqliteTable(
|
|
228
255
|
* "verificationToken",
|
|
229
256
|
* {
|
|
230
257
|
* identifier: text("identifier").notNull(),
|
|
231
|
-
* token: text("token").notNull(),
|
|
258
|
+
* token: text("token").notNull().unique(),
|
|
232
259
|
* expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
|
233
260
|
* },
|
|
234
261
|
* (vt) => ({
|
|
@@ -245,5 +272,5 @@ import type { Adapter } from "@auth/core/adapters";
|
|
|
245
272
|
* ---
|
|
246
273
|
*
|
|
247
274
|
**/
|
|
248
|
-
export declare function DrizzleAdapter<SqlFlavor extends SqlFlavorOptions>(db: SqlFlavor,
|
|
275
|
+
export declare function DrizzleAdapter<SqlFlavor extends SqlFlavorOptions>(db: SqlFlavor, schema?: DefaultSchema<SqlFlavor>): Adapter;
|
|
249
276
|
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AASH,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEhE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,+BAA+B,GAChC,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,6BAA6B,GAC9B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAClB,4BAA4B,GAC7B,MAAM,gBAAgB,CAAA;AACvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA2PI;AACJ,wBAAgB,cAAc,CAAC,SAAS,SAAS,gBAAgB,EAC/D,EAAE,EAAE,SAAS,EACb,MAAM,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,GAChC,OAAO,CAYT"}
|
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: 16}}>
|
|
3
3
|
* <p style={{fontWeight: "normal"}}>Official <a href="https://orm.drizzle.team">Drizzle ORM</a> adapter for Auth.js / NextAuth.js.</p>
|
|
4
4
|
* <a href="https://orm.drizzle.team">
|
|
5
|
-
* <img style={{display: "block"}} src="/img/adapters/drizzle
|
|
5
|
+
* <img style={{display: "block"}} src="/img/adapters/drizzle.svg" width="38" />
|
|
6
6
|
* </a>
|
|
7
7
|
* </div>
|
|
8
8
|
*
|
|
@@ -15,37 +15,51 @@
|
|
|
15
15
|
*
|
|
16
16
|
* @module @auth/drizzle-adapter
|
|
17
17
|
*/
|
|
18
|
+
import { is } from "drizzle-orm";
|
|
18
19
|
import { MySqlDatabase } from "drizzle-orm/mysql-core";
|
|
19
20
|
import { PgDatabase } from "drizzle-orm/pg-core";
|
|
20
21
|
import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core";
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
22
|
+
import { MySqlDrizzleAdapter } from "./lib/mysql.js";
|
|
23
|
+
import { PostgresDrizzleAdapter } from "./lib/pg.js";
|
|
23
24
|
import { SQLiteDrizzleAdapter } from "./lib/sqlite.js";
|
|
24
|
-
|
|
25
|
+
export { postgresUsersTable, postgresAccountsTable, postgresSessionsTable, postgresVerificationTokensTable, } from "./lib/pg.js";
|
|
26
|
+
export { sqliteUsersTable, sqliteAccountsTable, sqliteSessionsTable, sqliteVerificationTokensTable, } from "./lib/sqlite.js";
|
|
27
|
+
export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificationTokensTable, } from "./lib/mysql.js";
|
|
25
28
|
/**
|
|
26
|
-
* Add
|
|
29
|
+
* Add this adapter to your `auth.ts` Auth.js configuration object:
|
|
27
30
|
*
|
|
28
|
-
* ```ts title="
|
|
31
|
+
* ```ts title="auth.ts"
|
|
29
32
|
* import NextAuth from "next-auth"
|
|
30
|
-
* import
|
|
33
|
+
* import Google from "next-auth/providers/google"
|
|
31
34
|
* import { DrizzleAdapter } from "@auth/drizzle-adapter"
|
|
32
35
|
* import { db } from "./schema"
|
|
33
36
|
*
|
|
34
|
-
* export
|
|
37
|
+
* export const { handlers, auth } = NextAuth({
|
|
35
38
|
* adapter: DrizzleAdapter(db),
|
|
36
39
|
* providers: [
|
|
37
|
-
*
|
|
38
|
-
* clientId: process.env.GOOGLE_CLIENT_ID,
|
|
39
|
-
* clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
|
40
|
-
* }),
|
|
40
|
+
* Google,
|
|
41
41
|
* ],
|
|
42
42
|
* })
|
|
43
43
|
* ```
|
|
44
44
|
*
|
|
45
45
|
* :::info
|
|
46
|
-
* If you
|
|
46
|
+
* If you want to use your own tables, you can pass them as a second argument
|
|
47
47
|
* :::
|
|
48
48
|
*
|
|
49
|
+
* ```ts title="auth.ts"
|
|
50
|
+
* import NextAuth from "next-auth"
|
|
51
|
+
* import Google from "next-auth/providers/google"
|
|
52
|
+
* import { DrizzleAdapter } from "@auth/drizzle-adapter"
|
|
53
|
+
* import { db, accounts, sessions, users, verificationTokens } from "./schema"
|
|
54
|
+
*
|
|
55
|
+
* export const { handlers, auth } = NextAuth({
|
|
56
|
+
* adapter: DrizzleAdapter(db, { usersTable: users, accountsTable: accounts, sessionsTable: sessions, verificationTokensTable: verificationTokens }),
|
|
57
|
+
* providers: [
|
|
58
|
+
* Google,
|
|
59
|
+
* ],
|
|
60
|
+
* })
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
49
63
|
* ## Setup
|
|
50
64
|
*
|
|
51
65
|
* First, create a schema that includes [the minimum requirements for a `next-auth` adapter](/reference/core/adapters#models). You can select your favorite SQL flavor below and copy it.
|
|
@@ -66,11 +80,12 @@ import { is } from "drizzle-orm";
|
|
|
66
80
|
* integer
|
|
67
81
|
* } from "drizzle-orm/pg-core"
|
|
68
82
|
* import type { AdapterAccount } from '@auth/core/adapters'
|
|
83
|
+
* import { randomUUID } from "crypto"
|
|
69
84
|
*
|
|
70
85
|
* export const users = pgTable("user", {
|
|
71
|
-
* id: text("id").
|
|
86
|
+
* id: text("id").primaryKey().$defaultFn(() => randomUUID()),
|
|
72
87
|
* name: text("name"),
|
|
73
|
-
* email: text("email").notNull(),
|
|
88
|
+
* email: text("email").notNull().unique(),
|
|
74
89
|
* emailVerified: timestamp("emailVerified", { mode: "date" }),
|
|
75
90
|
* image: text("image"),
|
|
76
91
|
* })
|
|
@@ -81,7 +96,7 @@ import { is } from "drizzle-orm";
|
|
|
81
96
|
* userId: text("userId")
|
|
82
97
|
* .notNull()
|
|
83
98
|
* .references(() => users.id, { onDelete: "cascade" }),
|
|
84
|
-
* type: text("type")
|
|
99
|
+
* type: text("type").notNull(),
|
|
85
100
|
* provider: text("provider").notNull(),
|
|
86
101
|
* providerAccountId: text("providerAccountId").notNull(),
|
|
87
102
|
* refresh_token: text("refresh_token"),
|
|
@@ -93,23 +108,27 @@ import { is } from "drizzle-orm";
|
|
|
93
108
|
* session_state: text("session_state"),
|
|
94
109
|
* },
|
|
95
110
|
* (account) => ({
|
|
111
|
+
* userIdIdx: index().on(account.userId),
|
|
96
112
|
* compoundKey: primaryKey({ columns: [account.provider, account.providerAccountId] }),
|
|
97
113
|
* })
|
|
98
114
|
* )
|
|
99
115
|
*
|
|
100
116
|
* export const sessions = pgTable("session", {
|
|
101
|
-
*
|
|
117
|
+
* id: text("id").primaryKey().$defaultFn(() => randomUUID()),
|
|
118
|
+
* sessionToken: text("sessionToken").notNull().unique(),
|
|
102
119
|
* userId: text("userId")
|
|
103
120
|
* .notNull()
|
|
104
121
|
* .references(() => users.id, { onDelete: "cascade" }),
|
|
105
122
|
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
106
|
-
* })
|
|
123
|
+
* }, (session) => ({
|
|
124
|
+
* userIdIdx: index().on(session.userId)
|
|
125
|
+
* }))
|
|
107
126
|
*
|
|
108
127
|
* export const verificationTokens = pgTable(
|
|
109
128
|
* "verificationToken",
|
|
110
129
|
* {
|
|
111
130
|
* identifier: text("identifier").notNull(),
|
|
112
|
-
* token: text("token").notNull(),
|
|
131
|
+
* token: text("token").notNull().unique(),
|
|
113
132
|
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
114
133
|
* },
|
|
115
134
|
* (vt) => ({
|
|
@@ -131,10 +150,10 @@ import { is } from "drizzle-orm";
|
|
|
131
150
|
* import type { AdapterAccount } from "@auth/core/adapters"
|
|
132
151
|
*
|
|
133
152
|
* export const users = mysqlTable("user", {
|
|
134
|
-
* id: varchar("id", { length: 255 }).
|
|
153
|
+
* id: varchar("id", { length: 255 }).primaryKey().$defaultFn(() => randomUUID()),
|
|
135
154
|
* name: varchar("name", { length: 255 }),
|
|
136
|
-
* email: varchar("email", { length: 255 }).notNull(),
|
|
137
|
-
*
|
|
155
|
+
* email: varchar("email", { length: 255 }).notNull().unique(),
|
|
156
|
+
* emailVerified: timestamp("emailVerified", { mode: "date", fsp: 3 }),
|
|
138
157
|
* image: varchar("image", { length: 255 }),
|
|
139
158
|
* })
|
|
140
159
|
*
|
|
@@ -144,8 +163,8 @@ import { is } from "drizzle-orm";
|
|
|
144
163
|
* userId: varchar("userId", { length: 255 })
|
|
145
164
|
* .notNull()
|
|
146
165
|
* .references(() => users.id, { onDelete: "cascade" }),
|
|
147
|
-
* type: varchar("type", { length: 255 })
|
|
148
|
-
*
|
|
166
|
+
* type: varchar("type", { length: 255 }).notNull(),
|
|
167
|
+
* provider: varchar("provider", { length: 255 }).notNull(),
|
|
149
168
|
* providerAccountId: varchar("providerAccountId", { length: 255 }).notNull(),
|
|
150
169
|
* refresh_token: varchar("refresh_token", { length: 255 }),
|
|
151
170
|
* access_token: varchar("access_token", { length: 255 }),
|
|
@@ -159,22 +178,26 @@ import { is } from "drizzle-orm";
|
|
|
159
178
|
* compoundKey: primaryKey({
|
|
160
179
|
columns: [account.provider, account.providerAccountId],
|
|
161
180
|
}),
|
|
181
|
+
userIdIdx: index('Account_userId_index').on(account.userId)
|
|
162
182
|
* })
|
|
163
183
|
* )
|
|
164
184
|
*
|
|
165
185
|
* export const sessions = mysqlTable("session", {
|
|
166
|
-
*
|
|
186
|
+
* id: varchar("id", { length: 255 }).primaryKey().$defaultFn(() => randomUUID()),
|
|
187
|
+
* sessionToken: varchar("sessionToken", { length: 255 }).notNull().unique(),
|
|
167
188
|
* userId: varchar("userId", { length: 255 })
|
|
168
189
|
* .notNull()
|
|
169
190
|
* .references(() => users.id, { onDelete: "cascade" }),
|
|
170
191
|
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
171
|
-
* })
|
|
192
|
+
* }, (session) => ({
|
|
193
|
+
* userIdIdx: index('Session_userId_index').on(session.userId)
|
|
194
|
+
* }))
|
|
172
195
|
*
|
|
173
196
|
* export const verificationTokens = mysqlTable(
|
|
174
197
|
* "verificationToken",
|
|
175
198
|
* {
|
|
176
199
|
* identifier: varchar("identifier", { length: 255 }).notNull(),
|
|
177
|
-
* token: varchar("token", { length: 255 }).notNull(),
|
|
200
|
+
* token: varchar("token", { length: 255 }).notNull().unique(),
|
|
178
201
|
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
179
202
|
* },
|
|
180
203
|
* (vt) => ({
|
|
@@ -190,9 +213,9 @@ import { is } from "drizzle-orm";
|
|
|
190
213
|
* import type { AdapterAccount } from "@auth/core/adapters"
|
|
191
214
|
*
|
|
192
215
|
* export const users = sqliteTable("user", {
|
|
193
|
-
* id: text("id").
|
|
216
|
+
* id: text("id").primaryKey().$defaultFn(() => randomUUID()),
|
|
194
217
|
* name: text("name"),
|
|
195
|
-
* email: text("email").notNull(),
|
|
218
|
+
* email: text("email").notNull().unique(),
|
|
196
219
|
* emailVerified: integer("emailVerified", { mode: "timestamp_ms" }),
|
|
197
220
|
* image: text("image"),
|
|
198
221
|
* })
|
|
@@ -203,7 +226,7 @@ import { is } from "drizzle-orm";
|
|
|
203
226
|
* userId: text("userId")
|
|
204
227
|
* .notNull()
|
|
205
228
|
* .references(() => users.id, { onDelete: "cascade" }),
|
|
206
|
-
* type: text("type")
|
|
229
|
+
* type: text("type").notNull(),
|
|
207
230
|
* provider: text("provider").notNull(),
|
|
208
231
|
* providerAccountId: text("providerAccountId").notNull(),
|
|
209
232
|
* refresh_token: text("refresh_token"),
|
|
@@ -218,22 +241,26 @@ import { is } from "drizzle-orm";
|
|
|
218
241
|
* compoundKey: primaryKey({
|
|
219
242
|
columns: [account.provider, account.providerAccountId],
|
|
220
243
|
}),
|
|
244
|
+
userIdIdx: index('Account_userId_index').on(account.userId)
|
|
221
245
|
* })
|
|
222
246
|
* )
|
|
223
247
|
*
|
|
224
248
|
* export const sessions = sqliteTable("session", {
|
|
225
|
-
*
|
|
249
|
+
* id: text("id").primaryKey().$defaultFn(() => randomUUID())
|
|
250
|
+
* sessionToken: text("sessionToken").notNull().unique(),
|
|
226
251
|
* userId: text("userId")
|
|
227
252
|
* .notNull()
|
|
228
253
|
* .references(() => users.id, { onDelete: "cascade" }),
|
|
229
254
|
* expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
|
230
|
-
* })
|
|
255
|
+
* }, (table) => ({
|
|
256
|
+
* userIdIdx: index('Session_userId_index').on(table.userId)
|
|
257
|
+
* }))
|
|
231
258
|
*
|
|
232
259
|
* export const verificationTokens = sqliteTable(
|
|
233
260
|
* "verificationToken",
|
|
234
261
|
* {
|
|
235
262
|
* identifier: text("identifier").notNull(),
|
|
236
|
-
* token: text("token").notNull(),
|
|
263
|
+
* token: text("token").notNull().unique(),
|
|
237
264
|
* expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
|
238
265
|
* },
|
|
239
266
|
* (vt) => ({
|
|
@@ -250,15 +277,15 @@ import { is } from "drizzle-orm";
|
|
|
250
277
|
* ---
|
|
251
278
|
*
|
|
252
279
|
**/
|
|
253
|
-
export function DrizzleAdapter(db,
|
|
280
|
+
export function DrizzleAdapter(db, schema) {
|
|
254
281
|
if (is(db, MySqlDatabase)) {
|
|
255
|
-
return
|
|
282
|
+
return MySqlDrizzleAdapter(db, schema);
|
|
256
283
|
}
|
|
257
284
|
else if (is(db, PgDatabase)) {
|
|
258
|
-
return
|
|
285
|
+
return PostgresDrizzleAdapter(db, schema);
|
|
259
286
|
}
|
|
260
287
|
else if (is(db, BaseSQLiteDatabase)) {
|
|
261
|
-
return SQLiteDrizzleAdapter(db,
|
|
288
|
+
return SQLiteDrizzleAdapter(db, schema);
|
|
262
289
|
}
|
|
263
290
|
throw new Error(`Unsupported database type (${typeof db}) in Auth.js Drizzle adapter.`);
|
|
264
291
|
}
|