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
docs: update middleware.ts references to proxy.ts for Next.js 16 (#13373)
Next.js 16 renamed middleware.ts to proxy.ts and the exported function
from middleware to proxy. This updates all documentation references
across installation, session protection, edge compatibility, migration,
RBAC, passkey, and Prisma adapter pages to reflect the new convention.
Co-authored-by: FGameIn <fares.galal@gamein.ae>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/pages/concepts/index.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,9 +57,9 @@ Yes! Check out the [TypeScript docs](/getting-started/typescript)
57
57
58
58
</Accordion>
59
59
60
-
<Accordiontitle="Is Auth.js compatible with Next.js 12 Middleware?">
60
+
<Accordiontitle="Is Auth.js compatible with Next.js Proxy / Middleware?">
61
61
62
-
[Next.js middleware](https://nextjs.org/docs/middleware) is supported and is recommended as of version 5. An example middlewaresetup can be found [here](/getting-started/session-management/protecting#nextjs-middleware).
62
+
Yes! As of Next.js 16, `middleware.ts` has been renamed to `proxy.ts`. Auth.js supports both the new `proxy.ts` convention and the legacy `middleware.ts`. An example setup can be found [here](/getting-started/session-management/protecting#nextjs-proxy).
We recommend using version `@prisma/client@5.12.0` or above if using
69
-
middleware or any other edge runtime(s). See [edge
70
-
compatibility](#edge-compatibility) below for more information.
68
+
We recommend using version `@prisma/client@5.12.0` or above if using proxy (or
69
+
middleware in older Next.js versions) or any other edge runtime(s). In Next.js
70
+
16+, `proxy.ts` runs on the Node.js runtime, so this may no longer be
71
+
necessary. See [edge compatibility](#edge-compatibility) below for more
72
+
information.
71
73
</Callout>
72
74
73
75
<Code>
@@ -152,9 +154,9 @@ At the moment, Prisma is still working on being fully compatible with edge runti
152
154
- Use the Prisma's [Accelerate](https://pris.ly/d/accelerate) feature
153
155
- 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.
154
156
155
-
Using Prisma with the `jwt` session strategy and `@prisma/client@5.9.1` or above doesn't require any additional modifications, other than ensuring you don't do any database queries in your middleware.
157
+
Using Prisma with the `jwt` session strategy and `@prisma/client@5.9.1` or above doesn't require any additional modifications, other than ensuring you don't do any database queries in your proxy (or middleware in older Next.js versions).
156
158
157
-
Since `@prisma/client@5.9.1`, 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.
159
+
Since `@prisma/client@5.9.1`, 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 proxy as long as you do not execute any queries in your proxy.
Copy file name to clipboardExpand all lines: docs/pages/getting-started/migrating-to-v5.mdx
+19-19Lines changed: 19 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ npm install next-auth@beta
42
42
- OAuth 1.0 support is deprecated.
43
43
- The minimum required Next.js version is now [14.0](https://nextjs.org/14).
44
44
- The import `next-auth/next` is replaced. See [Authenticating server-side](#authenticating-server-side) for more details.
45
-
- The import `next-auth/middleware` is replaced. See [Authenticating server-side](#authenticating-server-side) for more details.
45
+
- The import `next-auth/middleware` is replaced. See [Authenticating server-side](#authenticating-server-side) for more details. As of Next.js 16, `middleware.ts` has been renamed to `proxy.ts`.
46
46
- When the `idToken: boolean` option is set to `false`, it won't entirely disable the ID token. Instead, it signals `next-auth` to also visit the `userinfo_endpoint` for the final user data. Previously, `idToken: false` opted out to check the `id_token` validity at all.
47
47
48
48
## Migration
@@ -92,7 +92,7 @@ See the table below for a summary of the changes. Below that are `diff` examples
Check out additional [Middleware docs](/getting-started/session-management/protecting#nextjs-middleware) for more details.
168
+
Check out additional [Proxy docs](/getting-started/session-management/protecting#nextjs-proxy) for more details.
169
169
170
170
</Tabs.Tab>
171
171
<Tabs.Tab>
@@ -258,7 +258,7 @@ While Auth.js strictly uses standard [Web APIs](https://developer.mozilla.org/en
258
258
259
259
Auth.js supports two [session strategies](/concepts/session-strategies). When you are using an adapter, it will default to the `database` strategy. **Unless your database and its adapter is compatible with the Edge runtime/infrastructure, you will not be able to use the `"database"` session strategy**.
260
260
261
-
So for example, if you are using an adapter that relies on an ORM/library that is not yet compatible with Edge runtime(s) below is an example where we force the `jwt` strategy and split up the configuration so the library doesn't attempt to access the database in edge environments, like in the middleware.
261
+
So for example, if you are using an adapter that relies on an ORM/library that is not yet compatible with Edge runtime(s) below is an example where we force the `jwt` strategy and split up the configuration so the library doesn't attempt to access the database in edge environments, like in the proxy (or middleware for older Next.js versions).
262
262
263
263
<Callout>
264
264
The following filenames are only a convention, they can be named anything you
3. In your middleware file, import the configuration object from your first `auth.config.ts` file and use it to lazily initialize Auth.js there. In effect, initialize Auth.js separately with all of your common options, but **without the edge incompatible adapter**.
294
+
3. In your proxy file (or middleware file for older Next.js versions), import the configuration object from your first `auth.config.ts` file and use it to lazily initialize Auth.js there. In effect, initialize Auth.js separately with all of your common options, but **without the edge incompatible adapter**.
295
295
296
-
```ts filename="middleware.ts" {1} /NextAuth/
296
+
```ts filename="proxy.ts" {1} /NextAuth/
297
297
importauthConfigfrom"./auth.config"
298
298
importNextAuthfrom"next-auth"
299
299
300
-
// Use only one of the two middleware options below
The above is just an example. **The main idea**, is to separate the part of the configuration that is edge-compatible from the rest, and only import the edge-compatible part in Middleware/Edge pages/routes. You can read more about this workaround in the [Prisma docs](/getting-started/adapters/prisma), for example.
311
+
The above is just an example. **The main idea**, is to separate the part of the configuration that is edge-compatible from the rest, and only import the edge-compatible part in Proxy/Edge pages/routes. You can read more about this workaround in the [Prisma docs](/getting-started/adapters/prisma), for example.
312
312
313
313
Please follow up with your library/database/ORM's maintainer to see if they are planning to support the Edge runtime/infrastructure.
Copy file name to clipboardExpand all lines: docs/pages/getting-started/providers/passkey.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -160,7 +160,7 @@ CREATE UNIQUE INDEX Authenticator_credentialID_key ON Authenticator(credentialID
160
160
161
161
#### Edge Compatibility
162
162
163
-
If you're using `next-auth` with Next.js and middleware, you should ensure that your database client of choice is "edge compatible". If you're using an older version of Prisma or another adapter that is not edge compatible, you'll need to make some adjustments. Check out our [edge compatibility](/guides/edge-compatibility) guide for more details. There is also Prisma specific information in the [Prisma adapter docs](/getting-started/adapters/prisma#edge-compatibility).
163
+
If you're using `next-auth` with Next.js and a proxy (or middleware in older versions), you should ensure that your database client of choice is "edge compatible" when using Next.js versions before 16. In Next.js 16+, `proxy.ts` runs on the Node.js runtime, so edge compatibility is no longer a concern. For older versions, check out our [edge compatibility](/guides/edge-compatibility) guide for more details. There is also Prisma specific information in the [Prisma adapter docs](/getting-started/adapters/prisma#edge-compatibility).
Copy file name to clipboardExpand all lines: docs/pages/getting-started/session-management/protecting.mdx
+18-11Lines changed: 18 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -240,12 +240,19 @@ API Routes are protected in the same way as any other route in Express, see [the
240
240
</Code.Express>
241
241
</Code>
242
242
243
-
### Next.js Middleware
243
+
### Next.js Proxy
244
244
245
-
With Next.js 12+, the easiest way to protect a set of pages is using the middleware file. You can create a `middleware.ts` file in your root pages directory with the following contents.
245
+
With Next.js 16+, the easiest way to protect a set of pages is using the proxy file. You can create a `proxy.ts` file in your root pages directory with the following contents.
246
246
247
-
```ts filename="middleware.ts"
248
-
export { authasmiddleware } from"@/auth"
247
+
<Callouttype="info">
248
+
As of Next.js 16, `middleware.ts` has been renamed to `proxy.ts` and the
249
+
exported function has been renamed from `middleware` to `proxy`. If you are
250
+
using an older version of Next.js, use `middleware.ts` and export `auth` as
251
+
`middleware` instead.
252
+
</Callout>
253
+
254
+
```ts filename="proxy.ts"
255
+
export { authasproxy } from"@/auth"
249
256
```
250
257
251
258
Then define `authorized` callback in your `auth.ts` file. For more details check out the [reference docs](/reference/nextjs#authorized).
You can also use a regex to match multiple routes or you can negate certain routes in order to protect all remaining routes. The following example avoids running the middleware on paths such as the favicon or static images.
286
+
You can also use a regex to match multiple routes or you can negate certain routes in order to protect all remaining routes. The following example avoids running the proxy on paths such as the favicon or static images.
Middleware will protect pages as defined by the `matcher` config export. For more details about the matcher, check out the [Next.js docs](https://nextjs.org/docs/pages/building-your-application/routing/middleware#matching-paths).
294
+
The proxy will protect pages as defined by the `matcher` config export. For more details about the matcher, check out the [Next.js docs](https://nextjs.org/docs/app/api-reference/file-conventions/proxy).
288
295
289
296
<Callout>
290
-
You should not rely on middleware exclusively for authorization. Always ensure
297
+
You should not rely on the proxy exclusively for authorization. Always ensure
291
298
that the session is verified as close to your data fetching as possible.
0 commit comments