@auth/drizzle-adapter 1.0.0 → 1.1.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 +1 -256
- package/index.d.ts.map +1 -1
- package/index.js +1 -256
- package/lib/mysql.d.ts +109 -240
- package/lib/mysql.d.ts.map +1 -1
- package/lib/mysql.js +70 -64
- package/lib/pg.d.ts +106 -238
- package/lib/pg.d.ts.map +1 -1
- package/lib/pg.js +63 -63
- package/lib/sqlite.d.ts +88 -220
- package/lib/sqlite.d.ts.map +1 -1
- package/lib/sqlite.js +65 -59
- package/lib/utils.d.ts +6 -6
- package/lib/utils.d.ts.map +1 -1
- package/package.json +7 -8
- package/src/index.ts +1 -271
- package/src/lib/mysql.ts +278 -96
- package/src/lib/pg.ts +272 -94
- package/src/lib/sqlite.ts +275 -91
- package/src/lib/utils.ts +14 -13
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
<img src="https://img.shields.io/npm/dm/@auth/drizzle-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
|
|
19
19
|
</a>
|
|
20
20
|
<a href="https://github.com/nextauthjs/next-auth/stargazers">
|
|
21
|
-
<img src="https://img.shields.io/github/stars/nextauthjs/next-auth?style=flat-square" alt="
|
|
21
|
+
<img src="https://img.shields.io/github/stars/nextauthjs/next-auth?style=flat-square" alt="GitHub Stars" />
|
|
22
22
|
</a>
|
|
23
23
|
</p>
|
|
24
24
|
</p>
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: 16}}>
|
|
3
|
-
* <p
|
|
3
|
+
* <p>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
5
|
* <img style={{display: "block"}} src="/img/adapters/drizzle.svg" width="38" />
|
|
6
6
|
* </a>
|
|
@@ -17,260 +17,5 @@
|
|
|
17
17
|
*/
|
|
18
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";
|
|
23
|
-
/**
|
|
24
|
-
* Add this adapter to your `auth.ts` Auth.js configuration object:
|
|
25
|
-
*
|
|
26
|
-
* ```ts title="auth.ts"
|
|
27
|
-
* import NextAuth from "next-auth"
|
|
28
|
-
* import Google from "next-auth/providers/google"
|
|
29
|
-
* import { DrizzleAdapter } from "@auth/drizzle-adapter"
|
|
30
|
-
* import { db } from "./schema"
|
|
31
|
-
*
|
|
32
|
-
* export const { handlers, auth } = NextAuth({
|
|
33
|
-
* adapter: DrizzleAdapter(db),
|
|
34
|
-
* providers: [
|
|
35
|
-
* Google,
|
|
36
|
-
* ],
|
|
37
|
-
* })
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* :::info
|
|
41
|
-
* If you want to use your own tables, you can pass them as a second argument
|
|
42
|
-
* :::
|
|
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
|
-
*
|
|
58
|
-
* ## Setup
|
|
59
|
-
*
|
|
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
|
-
* Additionally, you may extend the schema from the minimum requirements to suit your needs.
|
|
62
|
-
*
|
|
63
|
-
* - [Postgres](#postgres)
|
|
64
|
-
* - [MySQL](#mysql)
|
|
65
|
-
* - [SQLite](#sqlite)
|
|
66
|
-
*
|
|
67
|
-
* ### Postgres
|
|
68
|
-
|
|
69
|
-
* ```ts title="schema.ts"
|
|
70
|
-
* import {
|
|
71
|
-
* timestamp,
|
|
72
|
-
* pgTable,
|
|
73
|
-
* text,
|
|
74
|
-
* primaryKey,
|
|
75
|
-
* integer
|
|
76
|
-
* } from "drizzle-orm/pg-core"
|
|
77
|
-
* import type { AdapterAccount } from '@auth/core/adapters'
|
|
78
|
-
* import { randomUUID } from "crypto"
|
|
79
|
-
*
|
|
80
|
-
* export const users = pgTable("user", {
|
|
81
|
-
* id: text("id").primaryKey().$defaultFn(() => randomUUID()),
|
|
82
|
-
* name: text("name"),
|
|
83
|
-
* email: text("email").notNull().unique(),
|
|
84
|
-
* emailVerified: timestamp("emailVerified", { mode: "date" }),
|
|
85
|
-
* image: text("image"),
|
|
86
|
-
* })
|
|
87
|
-
*
|
|
88
|
-
* export const accounts = pgTable(
|
|
89
|
-
* "account",
|
|
90
|
-
* {
|
|
91
|
-
* userId: text("userId")
|
|
92
|
-
* .notNull()
|
|
93
|
-
* .references(() => users.id, { onDelete: "cascade" }),
|
|
94
|
-
* type: text("type").notNull(),
|
|
95
|
-
* provider: text("provider").notNull(),
|
|
96
|
-
* providerAccountId: text("providerAccountId").notNull(),
|
|
97
|
-
* refresh_token: text("refresh_token"),
|
|
98
|
-
* access_token: text("access_token"),
|
|
99
|
-
* expires_at: integer("expires_at"),
|
|
100
|
-
* token_type: text("token_type"),
|
|
101
|
-
* scope: text("scope"),
|
|
102
|
-
* id_token: text("id_token"),
|
|
103
|
-
* session_state: text("session_state"),
|
|
104
|
-
* },
|
|
105
|
-
* (account) => ({
|
|
106
|
-
* userIdIdx: index().on(account.userId),
|
|
107
|
-
* compoundKey: primaryKey({ columns: [account.provider, account.providerAccountId] }),
|
|
108
|
-
* })
|
|
109
|
-
* )
|
|
110
|
-
*
|
|
111
|
-
* export const sessions = pgTable("session", {
|
|
112
|
-
* id: text("id").primaryKey().$defaultFn(() => randomUUID()),
|
|
113
|
-
* sessionToken: text("sessionToken").notNull().unique(),
|
|
114
|
-
* userId: text("userId")
|
|
115
|
-
* .notNull()
|
|
116
|
-
* .references(() => users.id, { onDelete: "cascade" }),
|
|
117
|
-
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
118
|
-
* }, (session) => ({
|
|
119
|
-
* userIdIdx: index().on(session.userId)
|
|
120
|
-
* }))
|
|
121
|
-
*
|
|
122
|
-
* export const verificationTokens = pgTable(
|
|
123
|
-
* "verificationToken",
|
|
124
|
-
* {
|
|
125
|
-
* identifier: text("identifier").notNull(),
|
|
126
|
-
* token: text("token").notNull().unique(),
|
|
127
|
-
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
128
|
-
* },
|
|
129
|
-
* (vt) => ({
|
|
130
|
-
* compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
|
|
131
|
-
* })
|
|
132
|
-
* )
|
|
133
|
-
* ```
|
|
134
|
-
*
|
|
135
|
-
* ### MySQL
|
|
136
|
-
*
|
|
137
|
-
* ```ts title="schema.ts"
|
|
138
|
-
* import {
|
|
139
|
-
* int,
|
|
140
|
-
* timestamp,
|
|
141
|
-
* mysqlTable,
|
|
142
|
-
* primaryKey,
|
|
143
|
-
* varchar,
|
|
144
|
-
* } from "drizzle-orm/mysql-core"
|
|
145
|
-
* import type { AdapterAccount } from "@auth/core/adapters"
|
|
146
|
-
*
|
|
147
|
-
* export const users = mysqlTable("user", {
|
|
148
|
-
* id: varchar("id", { length: 255 }).primaryKey().$defaultFn(() => randomUUID()),
|
|
149
|
-
* name: varchar("name", { length: 255 }),
|
|
150
|
-
* email: varchar("email", { length: 255 }).notNull().unique(),
|
|
151
|
-
* emailVerified: timestamp("emailVerified", { mode: "date", fsp: 3 }),
|
|
152
|
-
* image: varchar("image", { length: 255 }),
|
|
153
|
-
* })
|
|
154
|
-
*
|
|
155
|
-
* export const accounts = mysqlTable(
|
|
156
|
-
* "account",
|
|
157
|
-
* {
|
|
158
|
-
* userId: varchar("userId", { length: 255 })
|
|
159
|
-
* .notNull()
|
|
160
|
-
* .references(() => users.id, { onDelete: "cascade" }),
|
|
161
|
-
* type: varchar("type", { length: 255 }).notNull(),
|
|
162
|
-
* provider: varchar("provider", { length: 255 }).notNull(),
|
|
163
|
-
* providerAccountId: varchar("providerAccountId", { length: 255 }).notNull(),
|
|
164
|
-
* refresh_token: varchar("refresh_token", { length: 255 }),
|
|
165
|
-
* access_token: varchar("access_token", { length: 255 }),
|
|
166
|
-
* expires_at: int("expires_at"),
|
|
167
|
-
* token_type: varchar("token_type", { length: 255 }),
|
|
168
|
-
* scope: varchar("scope", { length: 255 }),
|
|
169
|
-
* id_token: varchar("id_token", { length: 2048 }),
|
|
170
|
-
* session_state: varchar("session_state", { length: 255 }),
|
|
171
|
-
* },
|
|
172
|
-
* (account) => ({
|
|
173
|
-
* compoundKey: primaryKey({
|
|
174
|
-
columns: [account.provider, account.providerAccountId],
|
|
175
|
-
}),
|
|
176
|
-
userIdIdx: index('Account_userId_index').on(account.userId)
|
|
177
|
-
* })
|
|
178
|
-
* )
|
|
179
|
-
*
|
|
180
|
-
* export const sessions = mysqlTable("session", {
|
|
181
|
-
* id: varchar("id", { length: 255 }).primaryKey().$defaultFn(() => randomUUID()),
|
|
182
|
-
* sessionToken: varchar("sessionToken", { length: 255 }).notNull().unique(),
|
|
183
|
-
* userId: varchar("userId", { length: 255 })
|
|
184
|
-
* .notNull()
|
|
185
|
-
* .references(() => users.id, { onDelete: "cascade" }),
|
|
186
|
-
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
187
|
-
* }, (session) => ({
|
|
188
|
-
* userIdIdx: index('Session_userId_index').on(session.userId)
|
|
189
|
-
* }))
|
|
190
|
-
*
|
|
191
|
-
* export const verificationTokens = mysqlTable(
|
|
192
|
-
* "verificationToken",
|
|
193
|
-
* {
|
|
194
|
-
* identifier: varchar("identifier", { length: 255 }).notNull(),
|
|
195
|
-
* token: varchar("token", { length: 255 }).notNull().unique(),
|
|
196
|
-
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
197
|
-
* },
|
|
198
|
-
* (vt) => ({
|
|
199
|
-
* compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
|
|
200
|
-
* })
|
|
201
|
-
* )
|
|
202
|
-
* ```
|
|
203
|
-
*
|
|
204
|
-
* ### SQLite
|
|
205
|
-
*
|
|
206
|
-
* ```ts title="schema.ts"
|
|
207
|
-
* import { integer, sqliteTable, text, primaryKey } from "drizzle-orm/sqlite-core"
|
|
208
|
-
* import type { AdapterAccount } from "@auth/core/adapters"
|
|
209
|
-
*
|
|
210
|
-
* export const users = sqliteTable("user", {
|
|
211
|
-
* id: text("id").primaryKey().$defaultFn(() => randomUUID()),
|
|
212
|
-
* name: text("name"),
|
|
213
|
-
* email: text("email").notNull().unique(),
|
|
214
|
-
* emailVerified: integer("emailVerified", { mode: "timestamp_ms" }),
|
|
215
|
-
* image: text("image"),
|
|
216
|
-
* })
|
|
217
|
-
*
|
|
218
|
-
* export const accounts = sqliteTable(
|
|
219
|
-
* "account",
|
|
220
|
-
* {
|
|
221
|
-
* userId: text("userId")
|
|
222
|
-
* .notNull()
|
|
223
|
-
* .references(() => users.id, { onDelete: "cascade" }),
|
|
224
|
-
* type: text("type").notNull(),
|
|
225
|
-
* provider: text("provider").notNull(),
|
|
226
|
-
* providerAccountId: text("providerAccountId").notNull(),
|
|
227
|
-
* refresh_token: text("refresh_token"),
|
|
228
|
-
* access_token: text("access_token"),
|
|
229
|
-
* expires_at: integer("expires_at"),
|
|
230
|
-
* token_type: text("token_type"),
|
|
231
|
-
* scope: text("scope"),
|
|
232
|
-
* id_token: text("id_token"),
|
|
233
|
-
* session_state: text("session_state"),
|
|
234
|
-
* },
|
|
235
|
-
* (account) => ({
|
|
236
|
-
* compoundKey: primaryKey({
|
|
237
|
-
columns: [account.provider, account.providerAccountId],
|
|
238
|
-
}),
|
|
239
|
-
userIdIdx: index('Account_userId_index').on(account.userId)
|
|
240
|
-
* })
|
|
241
|
-
* )
|
|
242
|
-
*
|
|
243
|
-
* export const sessions = sqliteTable("session", {
|
|
244
|
-
* id: text("id").primaryKey().$defaultFn(() => randomUUID())
|
|
245
|
-
* sessionToken: text("sessionToken").notNull().unique(),
|
|
246
|
-
* userId: text("userId")
|
|
247
|
-
* .notNull()
|
|
248
|
-
* .references(() => users.id, { onDelete: "cascade" }),
|
|
249
|
-
* expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
|
250
|
-
* }, (table) => ({
|
|
251
|
-
* userIdIdx: index('Session_userId_index').on(table.userId)
|
|
252
|
-
* }))
|
|
253
|
-
*
|
|
254
|
-
* export const verificationTokens = sqliteTable(
|
|
255
|
-
* "verificationToken",
|
|
256
|
-
* {
|
|
257
|
-
* identifier: text("identifier").notNull(),
|
|
258
|
-
* token: text("token").notNull().unique(),
|
|
259
|
-
* expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
|
260
|
-
* },
|
|
261
|
-
* (vt) => ({
|
|
262
|
-
* compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
|
|
263
|
-
* })
|
|
264
|
-
* )
|
|
265
|
-
* ```
|
|
266
|
-
*
|
|
267
|
-
* ## Migrating your database
|
|
268
|
-
* With your schema now described in your code, you'll need to migrate your database to your schema.
|
|
269
|
-
*
|
|
270
|
-
* For full documentation on how to run migrations with Drizzle, [visit the Drizzle documentation](https://orm.drizzle.team/kit-docs/overview#running-migrations).
|
|
271
|
-
*
|
|
272
|
-
* ---
|
|
273
|
-
*
|
|
274
|
-
**/
|
|
275
20
|
export declare function DrizzleAdapter<SqlFlavor extends SqlFlavorOptions>(db: SqlFlavor, schema?: DefaultSchema<SqlFlavor>): Adapter;
|
|
276
21
|
//# 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;AASH,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEhE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,
|
|
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,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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: 16}}>
|
|
3
|
-
* <p
|
|
3
|
+
* <p>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
5
|
* <img style={{display: "block"}} src="/img/adapters/drizzle.svg" width="38" />
|
|
6
6
|
* </a>
|
|
@@ -22,261 +22,6 @@ import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core";
|
|
|
22
22
|
import { MySqlDrizzleAdapter } from "./lib/mysql.js";
|
|
23
23
|
import { PostgresDrizzleAdapter } from "./lib/pg.js";
|
|
24
24
|
import { SQLiteDrizzleAdapter } from "./lib/sqlite.js";
|
|
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";
|
|
28
|
-
/**
|
|
29
|
-
* Add this adapter to your `auth.ts` Auth.js configuration object:
|
|
30
|
-
*
|
|
31
|
-
* ```ts title="auth.ts"
|
|
32
|
-
* import NextAuth from "next-auth"
|
|
33
|
-
* import Google from "next-auth/providers/google"
|
|
34
|
-
* import { DrizzleAdapter } from "@auth/drizzle-adapter"
|
|
35
|
-
* import { db } from "./schema"
|
|
36
|
-
*
|
|
37
|
-
* export const { handlers, auth } = NextAuth({
|
|
38
|
-
* adapter: DrizzleAdapter(db),
|
|
39
|
-
* providers: [
|
|
40
|
-
* Google,
|
|
41
|
-
* ],
|
|
42
|
-
* })
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* :::info
|
|
46
|
-
* If you want to use your own tables, you can pass them as a second argument
|
|
47
|
-
* :::
|
|
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
|
-
*
|
|
63
|
-
* ## Setup
|
|
64
|
-
*
|
|
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
|
-
* Additionally, you may extend the schema from the minimum requirements to suit your needs.
|
|
67
|
-
*
|
|
68
|
-
* - [Postgres](#postgres)
|
|
69
|
-
* - [MySQL](#mysql)
|
|
70
|
-
* - [SQLite](#sqlite)
|
|
71
|
-
*
|
|
72
|
-
* ### Postgres
|
|
73
|
-
|
|
74
|
-
* ```ts title="schema.ts"
|
|
75
|
-
* import {
|
|
76
|
-
* timestamp,
|
|
77
|
-
* pgTable,
|
|
78
|
-
* text,
|
|
79
|
-
* primaryKey,
|
|
80
|
-
* integer
|
|
81
|
-
* } from "drizzle-orm/pg-core"
|
|
82
|
-
* import type { AdapterAccount } from '@auth/core/adapters'
|
|
83
|
-
* import { randomUUID } from "crypto"
|
|
84
|
-
*
|
|
85
|
-
* export const users = pgTable("user", {
|
|
86
|
-
* id: text("id").primaryKey().$defaultFn(() => randomUUID()),
|
|
87
|
-
* name: text("name"),
|
|
88
|
-
* email: text("email").notNull().unique(),
|
|
89
|
-
* emailVerified: timestamp("emailVerified", { mode: "date" }),
|
|
90
|
-
* image: text("image"),
|
|
91
|
-
* })
|
|
92
|
-
*
|
|
93
|
-
* export const accounts = pgTable(
|
|
94
|
-
* "account",
|
|
95
|
-
* {
|
|
96
|
-
* userId: text("userId")
|
|
97
|
-
* .notNull()
|
|
98
|
-
* .references(() => users.id, { onDelete: "cascade" }),
|
|
99
|
-
* type: text("type").notNull(),
|
|
100
|
-
* provider: text("provider").notNull(),
|
|
101
|
-
* providerAccountId: text("providerAccountId").notNull(),
|
|
102
|
-
* refresh_token: text("refresh_token"),
|
|
103
|
-
* access_token: text("access_token"),
|
|
104
|
-
* expires_at: integer("expires_at"),
|
|
105
|
-
* token_type: text("token_type"),
|
|
106
|
-
* scope: text("scope"),
|
|
107
|
-
* id_token: text("id_token"),
|
|
108
|
-
* session_state: text("session_state"),
|
|
109
|
-
* },
|
|
110
|
-
* (account) => ({
|
|
111
|
-
* userIdIdx: index().on(account.userId),
|
|
112
|
-
* compoundKey: primaryKey({ columns: [account.provider, account.providerAccountId] }),
|
|
113
|
-
* })
|
|
114
|
-
* )
|
|
115
|
-
*
|
|
116
|
-
* export const sessions = pgTable("session", {
|
|
117
|
-
* id: text("id").primaryKey().$defaultFn(() => randomUUID()),
|
|
118
|
-
* sessionToken: text("sessionToken").notNull().unique(),
|
|
119
|
-
* userId: text("userId")
|
|
120
|
-
* .notNull()
|
|
121
|
-
* .references(() => users.id, { onDelete: "cascade" }),
|
|
122
|
-
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
123
|
-
* }, (session) => ({
|
|
124
|
-
* userIdIdx: index().on(session.userId)
|
|
125
|
-
* }))
|
|
126
|
-
*
|
|
127
|
-
* export const verificationTokens = pgTable(
|
|
128
|
-
* "verificationToken",
|
|
129
|
-
* {
|
|
130
|
-
* identifier: text("identifier").notNull(),
|
|
131
|
-
* token: text("token").notNull().unique(),
|
|
132
|
-
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
133
|
-
* },
|
|
134
|
-
* (vt) => ({
|
|
135
|
-
* compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
|
|
136
|
-
* })
|
|
137
|
-
* )
|
|
138
|
-
* ```
|
|
139
|
-
*
|
|
140
|
-
* ### MySQL
|
|
141
|
-
*
|
|
142
|
-
* ```ts title="schema.ts"
|
|
143
|
-
* import {
|
|
144
|
-
* int,
|
|
145
|
-
* timestamp,
|
|
146
|
-
* mysqlTable,
|
|
147
|
-
* primaryKey,
|
|
148
|
-
* varchar,
|
|
149
|
-
* } from "drizzle-orm/mysql-core"
|
|
150
|
-
* import type { AdapterAccount } from "@auth/core/adapters"
|
|
151
|
-
*
|
|
152
|
-
* export const users = mysqlTable("user", {
|
|
153
|
-
* id: varchar("id", { length: 255 }).primaryKey().$defaultFn(() => randomUUID()),
|
|
154
|
-
* name: varchar("name", { length: 255 }),
|
|
155
|
-
* email: varchar("email", { length: 255 }).notNull().unique(),
|
|
156
|
-
* emailVerified: timestamp("emailVerified", { mode: "date", fsp: 3 }),
|
|
157
|
-
* image: varchar("image", { length: 255 }),
|
|
158
|
-
* })
|
|
159
|
-
*
|
|
160
|
-
* export const accounts = mysqlTable(
|
|
161
|
-
* "account",
|
|
162
|
-
* {
|
|
163
|
-
* userId: varchar("userId", { length: 255 })
|
|
164
|
-
* .notNull()
|
|
165
|
-
* .references(() => users.id, { onDelete: "cascade" }),
|
|
166
|
-
* type: varchar("type", { length: 255 }).notNull(),
|
|
167
|
-
* provider: varchar("provider", { length: 255 }).notNull(),
|
|
168
|
-
* providerAccountId: varchar("providerAccountId", { length: 255 }).notNull(),
|
|
169
|
-
* refresh_token: varchar("refresh_token", { length: 255 }),
|
|
170
|
-
* access_token: varchar("access_token", { length: 255 }),
|
|
171
|
-
* expires_at: int("expires_at"),
|
|
172
|
-
* token_type: varchar("token_type", { length: 255 }),
|
|
173
|
-
* scope: varchar("scope", { length: 255 }),
|
|
174
|
-
* id_token: varchar("id_token", { length: 2048 }),
|
|
175
|
-
* session_state: varchar("session_state", { length: 255 }),
|
|
176
|
-
* },
|
|
177
|
-
* (account) => ({
|
|
178
|
-
* compoundKey: primaryKey({
|
|
179
|
-
columns: [account.provider, account.providerAccountId],
|
|
180
|
-
}),
|
|
181
|
-
userIdIdx: index('Account_userId_index').on(account.userId)
|
|
182
|
-
* })
|
|
183
|
-
* )
|
|
184
|
-
*
|
|
185
|
-
* export const sessions = mysqlTable("session", {
|
|
186
|
-
* id: varchar("id", { length: 255 }).primaryKey().$defaultFn(() => randomUUID()),
|
|
187
|
-
* sessionToken: varchar("sessionToken", { length: 255 }).notNull().unique(),
|
|
188
|
-
* userId: varchar("userId", { length: 255 })
|
|
189
|
-
* .notNull()
|
|
190
|
-
* .references(() => users.id, { onDelete: "cascade" }),
|
|
191
|
-
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
192
|
-
* }, (session) => ({
|
|
193
|
-
* userIdIdx: index('Session_userId_index').on(session.userId)
|
|
194
|
-
* }))
|
|
195
|
-
*
|
|
196
|
-
* export const verificationTokens = mysqlTable(
|
|
197
|
-
* "verificationToken",
|
|
198
|
-
* {
|
|
199
|
-
* identifier: varchar("identifier", { length: 255 }).notNull(),
|
|
200
|
-
* token: varchar("token", { length: 255 }).notNull().unique(),
|
|
201
|
-
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
202
|
-
* },
|
|
203
|
-
* (vt) => ({
|
|
204
|
-
* compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
|
|
205
|
-
* })
|
|
206
|
-
* )
|
|
207
|
-
* ```
|
|
208
|
-
*
|
|
209
|
-
* ### SQLite
|
|
210
|
-
*
|
|
211
|
-
* ```ts title="schema.ts"
|
|
212
|
-
* import { integer, sqliteTable, text, primaryKey } from "drizzle-orm/sqlite-core"
|
|
213
|
-
* import type { AdapterAccount } from "@auth/core/adapters"
|
|
214
|
-
*
|
|
215
|
-
* export const users = sqliteTable("user", {
|
|
216
|
-
* id: text("id").primaryKey().$defaultFn(() => randomUUID()),
|
|
217
|
-
* name: text("name"),
|
|
218
|
-
* email: text("email").notNull().unique(),
|
|
219
|
-
* emailVerified: integer("emailVerified", { mode: "timestamp_ms" }),
|
|
220
|
-
* image: text("image"),
|
|
221
|
-
* })
|
|
222
|
-
*
|
|
223
|
-
* export const accounts = sqliteTable(
|
|
224
|
-
* "account",
|
|
225
|
-
* {
|
|
226
|
-
* userId: text("userId")
|
|
227
|
-
* .notNull()
|
|
228
|
-
* .references(() => users.id, { onDelete: "cascade" }),
|
|
229
|
-
* type: text("type").notNull(),
|
|
230
|
-
* provider: text("provider").notNull(),
|
|
231
|
-
* providerAccountId: text("providerAccountId").notNull(),
|
|
232
|
-
* refresh_token: text("refresh_token"),
|
|
233
|
-
* access_token: text("access_token"),
|
|
234
|
-
* expires_at: integer("expires_at"),
|
|
235
|
-
* token_type: text("token_type"),
|
|
236
|
-
* scope: text("scope"),
|
|
237
|
-
* id_token: text("id_token"),
|
|
238
|
-
* session_state: text("session_state"),
|
|
239
|
-
* },
|
|
240
|
-
* (account) => ({
|
|
241
|
-
* compoundKey: primaryKey({
|
|
242
|
-
columns: [account.provider, account.providerAccountId],
|
|
243
|
-
}),
|
|
244
|
-
userIdIdx: index('Account_userId_index').on(account.userId)
|
|
245
|
-
* })
|
|
246
|
-
* )
|
|
247
|
-
*
|
|
248
|
-
* export const sessions = sqliteTable("session", {
|
|
249
|
-
* id: text("id").primaryKey().$defaultFn(() => randomUUID())
|
|
250
|
-
* sessionToken: text("sessionToken").notNull().unique(),
|
|
251
|
-
* userId: text("userId")
|
|
252
|
-
* .notNull()
|
|
253
|
-
* .references(() => users.id, { onDelete: "cascade" }),
|
|
254
|
-
* expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
|
255
|
-
* }, (table) => ({
|
|
256
|
-
* userIdIdx: index('Session_userId_index').on(table.userId)
|
|
257
|
-
* }))
|
|
258
|
-
*
|
|
259
|
-
* export const verificationTokens = sqliteTable(
|
|
260
|
-
* "verificationToken",
|
|
261
|
-
* {
|
|
262
|
-
* identifier: text("identifier").notNull(),
|
|
263
|
-
* token: text("token").notNull().unique(),
|
|
264
|
-
* expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
|
265
|
-
* },
|
|
266
|
-
* (vt) => ({
|
|
267
|
-
* compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
|
|
268
|
-
* })
|
|
269
|
-
* )
|
|
270
|
-
* ```
|
|
271
|
-
*
|
|
272
|
-
* ## Migrating your database
|
|
273
|
-
* With your schema now described in your code, you'll need to migrate your database to your schema.
|
|
274
|
-
*
|
|
275
|
-
* For full documentation on how to run migrations with Drizzle, [visit the Drizzle documentation](https://orm.drizzle.team/kit-docs/overview#running-migrations).
|
|
276
|
-
*
|
|
277
|
-
* ---
|
|
278
|
-
*
|
|
279
|
-
**/
|
|
280
25
|
export function DrizzleAdapter(db, schema) {
|
|
281
26
|
if (is(db, MySqlDatabase)) {
|
|
282
27
|
return MySqlDrizzleAdapter(db, schema);
|