Skip to content

Commit 0ccef3d

Browse files
authored
chore(docs): improve edge compatibility (#11061)
1 parent 83f6668 commit 0ccef3d

File tree

2 files changed

+4
-45
lines changed

2 files changed

+4
-45
lines changed

docs/pages/getting-started/adapters/prisma.mdx

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -103,54 +103,12 @@ The original database edge-runtime workaround, to split your `auth.ts` configura
103103
At the moment, Prisma is still working on being fully compatible with edge runtimes like Vercel's. See the issue being tracked [here](https://github.com/prisma/prisma/issues/20560), and Prisma's announcement about early edge support in the `5.9.1` [changelog](https://github.com/prisma/prisma/releases/tag/5.9.0). There are two options to deal with this issue:
104104

105105
- Use the Prisma's [Accelerate](https://pris.ly/d/accelerate) feature
106-
- Switch to the `jwt` session strategy
106+
- Follow our [Edge Compatibility](/guides/edge-compatibility) page as the workaround. This uses the `jwt` session strategy and separates the `auth.ts` configuration into two files.
107107

108108
Using Prisma with the `jwt` session strategy and `@prisma/[email protected]` or above doesn't require any additional modifications, other than ensuring you don't do any database queries in your middleware.
109109

110110
Since `@prisma/[email protected]`, Prisma no longer throws about being incompatible with the edge runtime at instantiation, but at query time. Therefore, it is possible to import it in files being used in your middleware as long as you do not execute any queries in your middleware.
111111

112-
<Accordions>
113-
<Accordion title="Using '@prisma/client' before 'v5.9.1' requires some additional workarounds">
114-
115-
You will need to separate your Auth.js configuration into two files and use the [lazy initialization](/reference/next-auth#lazy-initialization) feature to instantiate a second copy of Auth.js in the middleware without the adapter.
116-
117-
Define the `auth.config.ts` file:
118-
119-
```ts filename="auth.config.ts"
120-
export default {
121-
providers: [GitHub, Google, Facebook, Twitter],
122-
} satisfies NextAuthConfig
123-
```
124-
125-
Import and use the `PrismaAdapter` in the `auth.ts` file. This is your main Auth.js configuration file that you'll use around the rest of your application.
126-
127-
```ts filename="auth.ts"
128-
import NextAuth from "next-auth"
129-
import authConfig from "./auth.config"
130-
import { PrismaAdapter } from "@auth/prisma-adapter"
131-
import { PrismaClient } from "@prisma/client"
132-
133-
globalThis.prisma ??= new PrismaClient()
134-
135-
export const { handlers, auth, signIn, signOut, unstable_update } = NextAuth({
136-
adapter: PrismaAdapter(globalThis.prisma),
137-
session: { strategy: "jwt" },
138-
...authConfig,
139-
})
140-
```
141-
142-
In the middleware file, however, import the first `auth.config` and instantiate a second instance of `NextAuth` using it as the configuration (note that the `adapter` is not used here to avoid the error).
143-
144-
```ts filename="middleware.ts"
145-
import NextAuth from "next-auth"
146-
import authConfig from "./auth.config"
147-
148-
export const middleware = NextAuth(authConfig).auth
149-
```
150-
151-
</Accordion>
152-
</Accordions>
153-
154112
### Schema
155113

156114
You need to use at least Prisma `2.26.0`. Create a schema file at `prisma/schema.prisma` with the following models.

docs/pages/guides/edge-compatibility.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ export default {
6767
} satisfies NextAuthConfig
6868
```
6969

70-
2. Next, a separate **instantiated** Auth.js instance which imports that configuration, but also adds the adapter.
70+
2. Next, a separate **instantiated** Auth.js instance which imports that configuration, but also adds the adapter and using `jwt` for the Session strategy:
7171

72-
```ts filename="auth.ts" {2, 10}
72+
```ts filename="auth.ts" {2, 10, 11}
7373
import NextAuth from "next-auth"
7474
import authConfig from "auth.config"
7575

@@ -80,6 +80,7 @@ const prisma = new PrismaClient()
8080

8181
export const { handlers, auth, signIn, signOut } = NextAuth({
8282
adapter: PrismaAdapter(prisma),
83+
session: { strategy: "jwt" },
8384
...authConfig,
8485
})
8586
```

0 commit comments

Comments
 (0)