You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This will work in code editors with a strong TypeScript integration like VSCode or WebStorm. It might not work if you're using more lightweight editors like VIM or Atom.
52
+
:::
53
+
17
54
## Module Augmentation
18
55
19
56
`next-auth` comes with certain types/interfaces, that are shared across submodules. Good examples are `Session` and `JWT`. Ideally, you should only need to create these types at a single place, and TS should pick them up in every location where they are referenced. Luckily, this is exactly what Module Augmentation can do for us. Define your shared interfaces in a single location, and get type-safety across your application, when you use `next-auth` (or one of its submodules).
Copy file name to clipboardExpand all lines: www/docs/schemas/adapters.md
+46-24Lines changed: 46 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,21 +5,21 @@ title: Database Adapters
5
5
6
6
An **Adapter** in NextAuth.js connects your application to whatever database or backend system you want to use to store data for user accounts, sessions, etc.
7
7
8
-
You do not need to specify an adapter explicitly unless you want to use advanced options such as custom models or schemas, if you want to use the Prisma adapter instead of the default TypeORM adapter, or if you are creating a custom adapter to connect to a database that is not one of the supported databases.
8
+
You do not need to specify an Adapter explicitly unless you want to use advanced options such as custom models or schemas, if you want to use the Prisma Adapter instead of the default TypeORM Adapter, or if you are creating a custom Adapter to connect to a database that is not one of the supported databases.
9
9
10
10
### Database Schemas
11
11
12
12
Configure your database by creating the tables and columns to match the schema expected by NextAuth.js.
13
13
14
-
*[MySQL Schema](/schemas/mysql)
15
-
*[Postgres Schema](/schemas/postgres)
16
-
*[Microsoft SQL Server Schema](/schemas/mssql)
14
+
-[MySQL Schema](/schemas/mysql)
15
+
-[Postgres Schema](/schemas/postgres)
16
+
-[Microsoft SQL Server Schema](/schemas/mssql)
17
17
18
18
## TypeORM Adapter
19
19
20
-
NextAuth.js comes with a default adapter that uses [TypeORM](https://typeorm.io/) so that it can be used with many different databases without any further configuration, you simply add the node module for the database driver you want to use to your project and pass a database connection string to NextAuth.js.
20
+
NextAuth.js comes with a default Adapter that uses [TypeORM](https://typeorm.io/) so that it can be used with many different databases without any further configuration, you simply add the node module for the database driver you want to use to your project and pass a database connection string to NextAuth.js.
21
21
22
-
The default adapter is the TypeORM adapter, the following configuration options are exactly equivalent.
22
+
The default Adapter is the TypeORM Adapter, the following configuration options are exactly equivalent.
23
23
24
24
```javascript
25
25
database: {
@@ -31,21 +31,21 @@ database: {
31
31
32
32
```javascript
33
33
adapter:Adapters.Default({
34
-
type:'sqlite',
35
-
database:':memory:',
36
-
synchronize:true
34
+
type:"sqlite",
35
+
database:":memory:",
36
+
synchronize:true,
37
37
})
38
38
```
39
39
40
40
```javascript
41
41
adapter:Adapters.TypeORM.Adapter({
42
-
type:'sqlite',
43
-
database:':memory:',
44
-
synchronize:true
42
+
type:"sqlite",
43
+
database:":memory:",
44
+
synchronize:true,
45
45
})
46
46
```
47
47
48
-
The tutorial [Custom models with TypeORM](/tutorials/typeorm-custom-models) explains how to extend the built in models and schemas used by the TypeORM adapter. You can use these models in your own code.
48
+
The tutorial [Custom models with TypeORM](/tutorials/typeorm-custom-models) explains how to extend the built in models and schemas used by the TypeORM Adapter. You can use these models in your own code.
49
49
50
50
:::tip
51
51
The `synchronize` option in TypeORM will generate SQL that exactly matches the documented schemas for MySQL and Postgres.
@@ -55,31 +55,31 @@ However, it should not be enabled against production databases as it may cause d
55
55
56
56
## Prisma Adapter
57
57
58
-
You can also use NextAuth.js with the experimental adapter for [Prisma 2](https://www.prisma.io/docs/).
58
+
You can also use NextAuth.js with the experimental Adapter for [Prisma 2](https://www.prisma.io/docs/).
59
59
60
-
To use this adapter, you need to install Prisma Client and Prisma CLI:
60
+
To use this Adapter, you need to install Prisma Client and Prisma CLI:
61
61
62
62
```
63
63
npm install @prisma/client
64
64
npm install prisma --save-dev
65
65
```
66
66
67
-
Configure your NextAuth.js to use the Prisma adapter:
67
+
Configure your NextAuth.js to use the Prisma Adapter:
@@ -232,9 +233,30 @@ if (process.env.NODE_ENV === "production") {
232
233
prisma =global.prisma
233
234
}
234
235
```
235
-
:::
236
236
237
+
:::
237
238
238
239
## Custom Adapter
239
240
240
-
See the tutorial for [creating a database adapter](/tutorials/creating-a-database-adapter) for more information on how to create a custom adapter. Have a look at the [adapters repository](https://github.com/nextauthjs/adapters) to see community maintained custom adapters or add your own.
241
+
See the tutorial for [creating a database Adapter](/tutorials/creating-a-database-adapter) for more information on how to create a custom Adapter. Have a look at the [Adapter repository](https://github.com/nextauthjs/adapters) to see community maintained custom Adapter or add your own.
242
+
243
+
### Editor integration
244
+
245
+
When writing your own custom Adapter in plain JavaScript, note that you can use **JSDoc** to get helpful editor hints and auto-completion like so:
This will work in code editors with a strong TypeScript integration like VSCode or WebStorm. It might not work if you're using more lightweight editors like VIM or Atom.
0 commit comments