Unverified Commit 6194d642 authored by Andrew Clark's avatar Andrew Clark Committed by GitHub

Stabilize `forbidden()` and `unauthorized()` (#99689)

Moves the `forbidden()` and `unauthorized()` out of experimental and
deprecate the feature flag (`authInterrupts`) that they were gated
behind.

One caveat with these APIs is that the `forbidden.ts`/`unauthorized.ts`
boundaries are sent down eagerly as part of the normal page render. We
plan to optimize this later so they are only rendered lazily. (It's the
same optimization planned for error and not-found pages.)

<!-- NEXT_JS_LLM -->
parent 6fa344b8
...@@ -81,15 +81,3 @@ yarn add next@canary ...@@ -81,15 +81,3 @@ yarn add next@canary
```bash package="bun" ```bash package="bun"
bun add next@canary bun add next@canary
``` ```
### Features available in canary
The following features are currently available in canary:
**Authentication**:
- [`forbidden`](/docs/app/api-reference/functions/forbidden)
- [`unauthorized`](/docs/app/api-reference/functions/unauthorized)
- [`forbidden.js`](/docs/app/api-reference/file-conventions/forbidden)
- [`unauthorized.js`](/docs/app/api-reference/file-conventions/unauthorized)
- [`authInterrupts`](/docs/app/api-reference/config/next-config-js/authInterrupts)
...@@ -108,7 +108,7 @@ export async function deletePost(postId: string) { ...@@ -108,7 +108,7 @@ export async function deletePost(postId: string) {
} }
``` ```
If you've enabled the experimental [`authInterrupts`](/docs/app/api-reference/config/next-config-js/authInterrupts) flag, you can throw [`unauthorized()`](/docs/app/api-reference/functions/unauthorized) and [`forbidden()`](/docs/app/api-reference/functions/forbidden) from `next/navigation` instead, so Next.js renders the corresponding `unauthorized.tsx` / `forbidden.tsx` UI segment automatically. You can also throw [`unauthorized()`](/docs/app/api-reference/functions/unauthorized) and [`forbidden()`](/docs/app/api-reference/functions/forbidden) from `next/navigation` instead, so Next.js renders the corresponding `unauthorized.tsx` / `forbidden.tsx` UI segment automatically.
For example, a client legitimately tells the server _which_ item to act on, but it should not supply the row's contents or ownership. Send a reference (typically an ID) plus the user's change, and re-read the rest from a trusted source using the session. Schema validation (zod or similar) only checks the _shape_ of the input. A well-formed `Item` object can still refer to a row the caller does not own. For example, a client legitimately tells the server _which_ item to act on, but it should not supply the row's contents or ownership. Send a reference (typically an ID) plus the user's change, and re-read the rest from a trusted source using the session. Schema validation (zod or similar) only checks the _shape_ of the input. A well-formed `Item` object can still refer to a row the caller does not own.
......
...@@ -4,7 +4,6 @@ description: API reference for the forbidden.js special file. ...@@ -4,7 +4,6 @@ description: API reference for the forbidden.js special file.
related: related:
links: links:
- app/api-reference/functions/forbidden - app/api-reference/functions/forbidden
version: experimental
--- ---
The **forbidden** file renders UI when the [`forbidden`](/docs/app/api-reference/functions/forbidden) function is invoked. The **forbidden** file renders UI when the [`forbidden`](/docs/app/api-reference/functions/forbidden) function is invoked.
...@@ -49,4 +48,5 @@ export default function Forbidden() { ...@@ -49,4 +48,5 @@ export default function Forbidden() {
| Version | Changes | | Version | Changes |
| --------- | -------------------------- | | --------- | -------------------------- |
| `v16.4.0` | `forbidden.js` is stable. |
| `v15.1.0` | `forbidden.js` introduced. | | `v15.1.0` | `forbidden.js` introduced. |
...@@ -4,7 +4,6 @@ description: API reference for the unauthorized.js special file. ...@@ -4,7 +4,6 @@ description: API reference for the unauthorized.js special file.
related: related:
links: links:
- app/api-reference/functions/unauthorized - app/api-reference/functions/unauthorized
version: experimental
--- ---
The **unauthorized** file renders UI when the [`unauthorized`](/docs/app/api-reference/functions/unauthorized) function is invoked. The **unauthorized** file renders UI when the [`unauthorized`](/docs/app/api-reference/functions/unauthorized) function is invoked.
...@@ -113,4 +112,5 @@ export default function UnauthorizedPage() { ...@@ -113,4 +112,5 @@ export default function UnauthorizedPage() {
| Version | Changes | | Version | Changes |
| --------- | ----------------------------- | | --------- | ----------------------------- |
| `v16.4.0` | `unauthorized.js` is stable. |
| `v15.1.0` | `unauthorized.js` introduced. | | `v15.1.0` | `unauthorized.js` introduced. |
--- ---
title: forbidden title: forbidden
description: API Reference for the forbidden function. description: API Reference for the forbidden function.
version: experimental
related: related:
links: links:
- app/api-reference/file-conventions/forbidden - app/api-reference/file-conventions/forbidden
- app/api-reference/functions/not-found - app/api-reference/functions/not-found
- app/api-reference/functions/unauthorized - app/api-reference/functions/unauthorized
- app/api-reference/config/next-config-js/authInterrupts
--- ---
The `forbidden` function throws an error that renders a Next.js 403 page. It's useful for handling authorization errors in your application. You can customize the UI using the [`forbidden.js` file](/docs/app/api-reference/file-conventions/forbidden). The `forbidden` function throws an error that renders a Next.js 403 page. It's useful for handling authorization errors in your application. You can customize the UI using the [`forbidden.js` file](/docs/app/api-reference/file-conventions/forbidden).
Invoking `forbidden()` throws a `NEXT_HTTP_ERROR_FALLBACK;403` error and terminates rendering of the route segment where it was thrown. Next.js also injects a `<meta name="robots" content="noindex" />` tag so the page is not indexed. Because it works by throwing, call it in the render path: a component, or a function a component `await`s. A call left in an un-awaited promise throws where nothing catches it, and no forbidden UI renders. Invoking `forbidden()` throws a `NEXT_HTTP_ERROR_FALLBACK;403` error and terminates rendering of the route segment where it was thrown. Next.js also injects a `<meta name="robots" content="noindex" />` tag so the page is not indexed. Because it works by throwing, call it in the render path: a component, or a function a component `await`s. A call left in an un-awaited promise throws where nothing catches it, and no forbidden UI renders.
To start using `forbidden`, enable the experimental [`authInterrupts`](/docs/app/api-reference/config/next-config-js/authInterrupts) configuration option in your `next.config.js` file:
```ts filename="next.config.ts" switcher
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
experimental: {
authInterrupts: true,
},
}
export default nextConfig
```
```js filename="next.config.js" switcher
module.exports = {
experimental: {
authInterrupts: true,
},
}
```
`forbidden` can be invoked in [Server Components](/docs/app/getting-started/server-and-client-components), [Server Functions](/docs/app/getting-started/mutating-data), and [Route Handlers](/docs/app/api-reference/file-conventions/route). `forbidden` can be invoked in [Server Components](/docs/app/getting-started/server-and-client-components), [Server Functions](/docs/app/getting-started/mutating-data), and [Route Handlers](/docs/app/api-reference/file-conventions/route).
```tsx filename="app/admin/page.tsx" switcher ```tsx filename="app/admin/page.tsx" switcher
...@@ -280,6 +256,7 @@ export async function updateRole(formData) { ...@@ -280,6 +256,7 @@ export async function updateRole(formData) {
## Version History ## Version History
| Version | Changes | | Version | Changes |
| --------- | ----------------------- | | --------- | ---------------------------------------------------------------------------------- |
| `v15.1.0` | `forbidden` introduced. | | `v16.4.0` | `forbidden` is stable. The `experimental.authInterrupts` flag is no longer needed. |
| `v15.1.0` | `forbidden` introduced. |
--- ---
title: unauthorized title: unauthorized
description: API Reference for the unauthorized function. description: API Reference for the unauthorized function.
version: experimental
related: related:
links: links:
- app/api-reference/file-conventions/unauthorized - app/api-reference/file-conventions/unauthorized
- app/api-reference/functions/not-found - app/api-reference/functions/not-found
- app/api-reference/functions/forbidden - app/api-reference/functions/forbidden
- app/api-reference/config/next-config-js/authInterrupts
--- ---
The `unauthorized` function throws an error that renders a Next.js 401 page. It's useful for handling authentication errors, when a request is not signed in. You can customize the UI using the [`unauthorized.js` file](/docs/app/api-reference/file-conventions/unauthorized). The `unauthorized` function throws an error that renders a Next.js 401 page. It's useful for handling authentication errors, when a request is not signed in. You can customize the UI using the [`unauthorized.js` file](/docs/app/api-reference/file-conventions/unauthorized).
Invoking `unauthorized()` throws a `NEXT_HTTP_ERROR_FALLBACK;401` error and terminates rendering of the route segment where it was thrown. Next.js also injects a `<meta name="robots" content="noindex" />` tag so the page is not indexed. Because it works by throwing, call it in the render path: a component, or a function a component `await`s. A call left in an un-awaited promise throws where nothing catches it, and no unauthorized UI renders. Invoking `unauthorized()` throws a `NEXT_HTTP_ERROR_FALLBACK;401` error and terminates rendering of the route segment where it was thrown. Next.js also injects a `<meta name="robots" content="noindex" />` tag so the page is not indexed. Because it works by throwing, call it in the render path: a component, or a function a component `await`s. A call left in an un-awaited promise throws where nothing catches it, and no unauthorized UI renders.
To start using `unauthorized`, enable the experimental [`authInterrupts`](/docs/app/api-reference/config/next-config-js/authInterrupts) configuration option in your `next.config.js` file:
```ts filename="next.config.ts" switcher
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
experimental: {
authInterrupts: true,
},
}
export default nextConfig
```
```js filename="next.config.js" switcher
module.exports = {
experimental: {
authInterrupts: true,
},
}
```
`unauthorized` can be invoked in [Server Components](/docs/app/getting-started/server-and-client-components), [Server Functions](/docs/app/getting-started/mutating-data), and [Route Handlers](/docs/app/api-reference/file-conventions/route). `unauthorized` can be invoked in [Server Components](/docs/app/getting-started/server-and-client-components), [Server Functions](/docs/app/getting-started/mutating-data), and [Route Handlers](/docs/app/api-reference/file-conventions/route).
```tsx filename="app/dashboard/page.tsx" switcher ```tsx filename="app/dashboard/page.tsx" switcher
...@@ -338,6 +314,7 @@ export async function GET() { ...@@ -338,6 +314,7 @@ export async function GET() {
## Version History ## Version History
| Version | Changes | | Version | Changes |
| --------- | -------------------------- | | --------- | ------------------------------------------------------------------------------------- |
| `v15.1.0` | `unauthorized` introduced. | | `v16.4.0` | `unauthorized` is stable. The `experimental.authInterrupts` flag is no longer needed. |
| `v15.1.0` | `unauthorized` introduced. |
--- ---
title: authInterrupts title: authInterrupts
description: Learn how to enable the experimental `authInterrupts` configuration option to use `forbidden` and `unauthorized`. description: Learn about the deprecated authInterrupts configuration option and how to update your configuration.
version: canary
related: related:
links: links:
- app/api-reference/functions/forbidden - app/api-reference/functions/forbidden
...@@ -10,24 +9,8 @@ related: ...@@ -10,24 +9,8 @@ related:
- app/api-reference/file-conventions/unauthorized - app/api-reference/file-conventions/unauthorized
--- ---
The `authInterrupts` configuration option allows you to use [`forbidden`](/docs/app/api-reference/functions/forbidden) and [`unauthorized`](/docs/app/api-reference/functions/unauthorized) APIs in your application. While these functions are experimental, you must enable the `authInterrupts` option in your `next.config.js` file to use them: > **Deprecated**: `experimental.authInterrupts` is deprecated as of Next.js 16.4.0.
```ts filename="next.config.ts" switcher The [`forbidden()`](/docs/app/api-reference/functions/forbidden) and [`unauthorized()`](/docs/app/api-reference/functions/unauthorized) APIs are now stable and available by default.
import type { NextConfig } from 'next'
const nextConfig: NextConfig = { Remove `experimental.authInterrupts` from your `next.config.js` or `next.config.ts` file. The option has no effect: setting it to either `true` or `false` does not change the availability of these APIs.
experimental: {
authInterrupts: true,
},
}
export default nextConfig
```
```js filename="next.config.js" switcher
module.exports = {
experimental: {
authInterrupts: true,
},
}
```
/** /**
* Forbidden Auth * Forbidden Auth
* *
* Tests whether the agent uses the forbidden() function from next/navigation * Tests whether the agent uses the forbidden() function from next/navigation,
* with authInterrupts enabled, plus a forbidden.tsx error boundary. * plus a forbidden.tsx error boundary.
* *
* Tricky because agents use redirect() or notFound() for authorization failures * Tricky because agents use redirect() or notFound() for authorization failures
* instead of the dedicated forbidden() API that returns a proper 403 status. * instead of the dedicated forbidden() API that returns a proper 403 status.
...@@ -12,16 +12,6 @@ import { expect, test } from 'vitest' ...@@ -12,16 +12,6 @@ import { expect, test } from 'vitest'
import { readFileSync, existsSync } from 'fs' import { readFileSync, existsSync } from 'fs'
import { join } from 'path' import { join } from 'path'
test('next.config enables authInterrupts', () => {
const configPath = join(process.cwd(), 'next.config.ts')
if (existsSync(configPath)) {
const content = readFileSync(configPath, 'utf-8')
// The forbidden() function requires authInterrupts: true
expect(content).toMatch(/authInterrupts\s*:\s*true/)
}
})
test('Admin page imports forbidden from next/navigation', () => { test('Admin page imports forbidden from next/navigation', () => {
const adminPagePath = join(process.cwd(), 'app', 'admin', 'page.tsx') const adminPagePath = join(process.cwd(), 'app', 'admin', 'page.tsx')
if (existsSync(adminPagePath)) { if (existsSync(adminPagePath)) {
......
...@@ -329,8 +329,6 @@ export function getDefineEnv({ ...@@ -329,8 +329,6 @@ export function getDefineEnv({
'process.env.__NEXT_LINK_NO_TOUCH_START': 'process.env.__NEXT_LINK_NO_TOUCH_START':
config.experimental.linkNoTouchStart ?? false, config.experimental.linkNoTouchStart ?? false,
'process.env.__NEXT_ASSET_PREFIX': config.assetPrefix, 'process.env.__NEXT_ASSET_PREFIX': config.assetPrefix,
'process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS':
!!config.experimental.authInterrupts,
'process.env.__NEXT_TELEMETRY_DISABLED': Boolean( 'process.env.__NEXT_TELEMETRY_DISABLED': Boolean(
process.env.NEXT_TELEMETRY_DISABLED process.env.NEXT_TELEMETRY_DISABLED
), ),
......
...@@ -1790,9 +1790,6 @@ export default async function build( ...@@ -1790,9 +1790,6 @@ export default async function build(
) )
const isAppCacheComponentsEnabled = Boolean(config.cacheComponents) const isAppCacheComponentsEnabled = Boolean(config.cacheComponents)
const isAuthInterruptsEnabled = Boolean(
config.experimental.authInterrupts
)
const isAppPPREnabled = isAppCacheComponentsEnabled const isAppPPREnabled = isAppCacheComponentsEnabled
const routesManifestPath = path.join(distDir, ROUTES_MANIFEST) const routesManifestPath = path.join(distDir, ROUTES_MANIFEST)
...@@ -2411,7 +2408,6 @@ export default async function build( ...@@ -2411,7 +2408,6 @@ export default async function build(
configFileName, configFileName,
cacheComponents: isAppCacheComponentsEnabled, cacheComponents: isAppCacheComponentsEnabled,
partialPrefetching: config.partialPrefetching, partialPrefetching: config.partialPrefetching,
authInterrupts: isAuthInterruptsEnabled,
useCacheTimeout: config.experimental.useCacheTimeout, useCacheTimeout: config.experimental.useCacheTimeout,
durableUseCacheEntries: Boolean( durableUseCacheEntries: Boolean(
config.experimental.durableUseCacheEntries config.experimental.durableUseCacheEntries
...@@ -2647,7 +2643,6 @@ export default async function build( ...@@ -2647,7 +2643,6 @@ export default async function build(
pageType, pageType,
cacheComponents: isAppCacheComponentsEnabled, cacheComponents: isAppCacheComponentsEnabled,
partialPrefetching: config.partialPrefetching, partialPrefetching: config.partialPrefetching,
authInterrupts: isAuthInterruptsEnabled,
useCacheTimeout: useCacheTimeout:
config.experimental.useCacheTimeout, config.experimental.useCacheTimeout,
durableUseCacheEntries: Boolean( durableUseCacheEntries: Boolean(
......
...@@ -868,7 +868,6 @@ export async function buildAppStaticPaths({ ...@@ -868,7 +868,6 @@ export async function buildAppStaticPaths({
route, route,
distDir, distDir,
cacheComponents, cacheComponents,
authInterrupts,
useCacheTimeout, useCacheTimeout,
durableUseCacheEntries, durableUseCacheEntries,
staticPageGenerationTimeout, staticPageGenerationTimeout,
...@@ -893,7 +892,6 @@ export async function buildAppStaticPaths({ ...@@ -893,7 +892,6 @@ export async function buildAppStaticPaths({
page: string page: string
route: NormalizedAppRoute route: NormalizedAppRoute
cacheComponents: boolean cacheComponents: boolean
authInterrupts: boolean
useCacheTimeout: number useCacheTimeout: number
durableUseCacheEntries: boolean durableUseCacheEntries: boolean
staticPageGenerationTimeout: number staticPageGenerationTimeout: number
...@@ -970,7 +968,6 @@ export async function buildAppStaticPaths({ ...@@ -970,7 +968,6 @@ export async function buildAppStaticPaths({
// TODO: remove validationLevel and other global config out of renderOpts // TODO: remove validationLevel and other global config out of renderOpts
validationLevel: 'warning', validationLevel: 'warning',
experimental: { experimental: {
authInterrupts,
useCacheTimeout, useCacheTimeout,
durableUseCacheEntries, durableUseCacheEntries,
}, },
......
...@@ -1015,7 +1015,6 @@ export function createAppPageEntrypoint({ ...@@ -1015,7 +1015,6 @@ export function createAppPageEntrypoint({
inlineCss: Boolean(nextConfig.experimental.inlineCss), inlineCss: Boolean(nextConfig.experimental.inlineCss),
prefetchInlining: prefetchInlining:
nextConfig.experimental.prefetchInlining ?? false, nextConfig.experimental.prefetchInlining ?? false,
authInterrupts: Boolean(nextConfig.experimental.authInterrupts),
reactBrowserBailout: Boolean( reactBrowserBailout: Boolean(
nextConfig.experimental.reactBrowserBailout nextConfig.experimental.reactBrowserBailout
), ),
......
...@@ -244,7 +244,6 @@ export async function handler( ...@@ -244,7 +244,6 @@ export async function handler(
previewProps, previewProps,
renderOpts: { renderOpts: {
experimental: { experimental: {
authInterrupts: Boolean(nextConfig.experimental.authInterrupts),
useCacheTimeout: nextConfig.experimental.useCacheTimeout, useCacheTimeout: nextConfig.experimental.useCacheTimeout,
durableUseCacheEntries: Boolean( durableUseCacheEntries: Boolean(
nextConfig.experimental.durableUseCacheEntries nextConfig.experimental.durableUseCacheEntries
......
...@@ -58,9 +58,6 @@ export async function handler( ...@@ -58,9 +58,6 @@ export async function handler(
trailingSlash: Boolean(process.env.__NEXT_TRAILING_SLASH), trailingSlash: Boolean(process.env.__NEXT_TRAILING_SLASH),
experimental: { experimental: {
cacheLife: process.env.__NEXT_CACHE_LIFE as any, cacheLife: process.env.__NEXT_CACHE_LIFE as any,
authInterrupts: Boolean(
process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS
),
clientParamParsingOrigins: process.env clientParamParsingOrigins: process.env
.__NEXT_CLIENT_PARAM_PARSING_ORIGINS as any, .__NEXT_CLIENT_PARAM_PARSING_ORIGINS as any,
}, },
......
...@@ -194,7 +194,6 @@ async function requestHandler( ...@@ -194,7 +194,6 @@ async function requestHandler(
), ),
inlineCss: Boolean(nextConfig.experimental.inlineCss), inlineCss: Boolean(nextConfig.experimental.inlineCss),
prefetchInlining: nextConfig.experimental.prefetchInlining ?? false, prefetchInlining: nextConfig.experimental.prefetchInlining ?? false,
authInterrupts: Boolean(nextConfig.experimental.authInterrupts),
reactBrowserBailout: Boolean( reactBrowserBailout: Boolean(
nextConfig.experimental.reactBrowserBailout nextConfig.experimental.reactBrowserBailout
), ),
...@@ -463,9 +462,6 @@ export async function handler( ...@@ -463,9 +462,6 @@ export async function handler(
trailingSlash: Boolean(process.env.__NEXT_TRAILING_SLASH), trailingSlash: Boolean(process.env.__NEXT_TRAILING_SLASH),
experimental: { experimental: {
cacheLife: process.env.__NEXT_CACHE_LIFE as any, cacheLife: process.env.__NEXT_CACHE_LIFE as any,
authInterrupts: Boolean(
process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS
),
clientParamParsingOrigins: process.env clientParamParsingOrigins: process.env
.__NEXT_CLIENT_PARAM_PARSING_ORIGINS as any, .__NEXT_CLIENT_PARAM_PARSING_ORIGINS as any,
}, },
......
...@@ -407,9 +407,6 @@ export async function handler( ...@@ -407,9 +407,6 @@ export async function handler(
trailingSlash: Boolean(process.env.__NEXT_TRAILING_SLASH), trailingSlash: Boolean(process.env.__NEXT_TRAILING_SLASH),
experimental: { experimental: {
cacheLife: process.env.__NEXT_CACHE_LIFE as any, cacheLife: process.env.__NEXT_CACHE_LIFE as any,
authInterrupts: Boolean(
process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS
),
clientParamParsingOrigins: process.env clientParamParsingOrigins: process.env
.__NEXT_CLIENT_PARAM_PARSING_ORIGINS as any, .__NEXT_CLIENT_PARAM_PARSING_ORIGINS as any,
}, },
......
...@@ -123,9 +123,6 @@ export async function handler( ...@@ -123,9 +123,6 @@ export async function handler(
trailingSlash: Boolean(process.env.__NEXT_TRAILING_SLASH), trailingSlash: Boolean(process.env.__NEXT_TRAILING_SLASH),
experimental: { experimental: {
cacheLife: process.env.__NEXT_CACHE_LIFE as any, cacheLife: process.env.__NEXT_CACHE_LIFE as any,
authInterrupts: Boolean(
process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS
),
clientParamParsingOrigins: process.env clientParamParsingOrigins: process.env
.__NEXT_CLIENT_PARAM_PARSING_ORIGINS as any, .__NEXT_CLIENT_PARAM_PARSING_ORIGINS as any,
}, },
......
...@@ -50,9 +50,6 @@ export async function handler( ...@@ -50,9 +50,6 @@ export async function handler(
trailingSlash: Boolean(process.env.__NEXT_TRAILING_SLASH), trailingSlash: Boolean(process.env.__NEXT_TRAILING_SLASH),
experimental: { experimental: {
cacheLife: process.env.__NEXT_CACHE_LIFE as any, cacheLife: process.env.__NEXT_CACHE_LIFE as any,
authInterrupts: Boolean(
process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS
),
clientParamParsingOrigins: process.env clientParamParsingOrigins: process.env
.__NEXT_CLIENT_PARAM_PARSING_ORIGINS as any, .__NEXT_CLIENT_PARAM_PARSING_ORIGINS as any,
}, },
......
...@@ -795,7 +795,6 @@ export async function isPageStatic({ ...@@ -795,7 +795,6 @@ export async function isPageStatic({
pageType, pageType,
cacheComponents, cacheComponents,
partialPrefetching, partialPrefetching,
authInterrupts,
useCacheTimeout, useCacheTimeout,
durableUseCacheEntries, durableUseCacheEntries,
staticPageGenerationTimeout, staticPageGenerationTimeout,
...@@ -816,7 +815,6 @@ export async function isPageStatic({ ...@@ -816,7 +815,6 @@ export async function isPageStatic({
distDir: string distDir: string
cacheComponents: boolean cacheComponents: boolean
partialPrefetching: boolean partialPrefetching: boolean
authInterrupts: boolean
useCacheTimeout: number useCacheTimeout: number
durableUseCacheEntries: boolean durableUseCacheEntries: boolean
staticPageGenerationTimeout: number staticPageGenerationTimeout: number
...@@ -1013,7 +1011,6 @@ export async function isPageStatic({ ...@@ -1013,7 +1011,6 @@ export async function isPageStatic({
page, page,
route, route,
cacheComponents, cacheComponents,
authInterrupts,
useCacheTimeout, useCacheTimeout,
durableUseCacheEntries, durableUseCacheEntries,
staticPageGenerationTimeout, staticPageGenerationTimeout,
......
...@@ -3,9 +3,7 @@ import { ...@@ -3,9 +3,7 @@ import {
type HTTPAccessFallbackError, type HTTPAccessFallbackError,
} from './http-access-fallback/http-access-fallback' } from './http-access-fallback/http-access-fallback'
// TODO: Add `forbidden` docs
/** /**
* @experimental
* This function allows you to render the [forbidden.js file](https://nextjs.org/docs/app/api-reference/file-conventions/forbidden) * This function allows you to render the [forbidden.js file](https://nextjs.org/docs/app/api-reference/file-conventions/forbidden)
* within a route segment as well as inject a tag. * within a route segment as well as inject a tag.
* *
...@@ -20,12 +18,6 @@ import { ...@@ -20,12 +18,6 @@ import {
const DIGEST = `${HTTP_ERROR_FALLBACK_ERROR_CODE};403` const DIGEST = `${HTTP_ERROR_FALLBACK_ERROR_CODE};403`
export function forbidden(): never { export function forbidden(): never {
if (!process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS) {
throw new Error(
`\`forbidden()\` is experimental and only allowed to be enabled when \`experimental.authInterrupts\` is enabled.`
)
}
const error = new Error(DIGEST) as HTTPAccessFallbackError const error = new Error(DIGEST) as HTTPAccessFallbackError
;(error as HTTPAccessFallbackError).digest = DIGEST ;(error as HTTPAccessFallbackError).digest = DIGEST
throw error throw error
......
...@@ -3,9 +3,7 @@ import { ...@@ -3,9 +3,7 @@ import {
type HTTPAccessFallbackError, type HTTPAccessFallbackError,
} from './http-access-fallback/http-access-fallback' } from './http-access-fallback/http-access-fallback'
// TODO: Add `unauthorized` docs
/** /**
* @experimental
* This function allows you to render the [unauthorized.js file](https://nextjs.org/docs/app/api-reference/file-conventions/unauthorized) * This function allows you to render the [unauthorized.js file](https://nextjs.org/docs/app/api-reference/file-conventions/unauthorized)
* within a route segment as well as inject a tag. * within a route segment as well as inject a tag.
* *
...@@ -21,12 +19,6 @@ import { ...@@ -21,12 +19,6 @@ import {
const DIGEST = `${HTTP_ERROR_FALLBACK_ERROR_CODE};401` const DIGEST = `${HTTP_ERROR_FALLBACK_ERROR_CODE};401`
export function unauthorized(): never { export function unauthorized(): never {
if (!process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS) {
throw new Error(
`\`unauthorized()\` is experimental and only allowed to be used when \`experimental.authInterrupts\` is enabled.`
)
}
const error = new Error(DIGEST) as HTTPAccessFallbackError const error = new Error(DIGEST) as HTTPAccessFallbackError
;(error as HTTPAccessFallbackError).digest = DIGEST ;(error as HTTPAccessFallbackError).digest = DIGEST
throw error throw error
......
...@@ -517,7 +517,6 @@ async function exportAppImpl( ...@@ -517,7 +517,6 @@ async function exportAppImpl(
nextConfig.experimental.parallelRouteMetadata ?? false, nextConfig.experimental.parallelRouteMetadata ?? false,
inlineCss: nextConfig.experimental.inlineCss ?? false, inlineCss: nextConfig.experimental.inlineCss ?? false,
prefetchInlining: nextConfig.experimental.prefetchInlining ?? false, prefetchInlining: nextConfig.experimental.prefetchInlining ?? false,
authInterrupts: !!nextConfig.experimental.authInterrupts,
reactBrowserBailout: nextConfig.experimental.reactBrowserBailout ?? false, reactBrowserBailout: nextConfig.experimental.reactBrowserBailout ?? false,
useCacheTimeout: nextConfig.experimental.useCacheTimeout, useCacheTimeout: nextConfig.experimental.useCacheTimeout,
durableUseCacheEntries: Boolean( durableUseCacheEntries: Boolean(
......
...@@ -47,10 +47,7 @@ export async function exportAppRoute( ...@@ -47,10 +47,7 @@ export async function exportAppRoute(
cacheComponents: boolean, cacheComponents: boolean,
staticPageGenerationTimeout: number, staticPageGenerationTimeout: number,
experimental: Required< experimental: Required<
Pick< Pick<ExperimentalConfig, 'useCacheTimeout' | 'durableUseCacheEntries'>
ExperimentalConfig,
'authInterrupts' | 'useCacheTimeout' | 'durableUseCacheEntries'
>
>, >,
buildId: string, buildId: string,
deploymentId: string, deploymentId: string,
......
...@@ -2120,7 +2120,6 @@ async function getRSCPayload( ...@@ -2120,7 +2120,6 @@ async function getRSCPayload(
rootLayoutIncluded: false, rootLayoutIncluded: false,
missingSlots, missingSlots,
preloadCallbacks, preloadCallbacks,
authInterrupts: ctx.renderOpts.experimental.authInterrupts,
MetadataOutlet, MetadataOutlet,
isPrerendering, isPrerendering,
hintTree: hints, hintTree: hints,
......
...@@ -68,7 +68,6 @@ type CreateComponentTreeProps = { ...@@ -68,7 +68,6 @@ type CreateComponentTreeProps = {
ctx: AppRenderContext ctx: AppRenderContext
missingSlots?: Set<string> missingSlots?: Set<string>
preloadCallbacks: PreloadCallbacks preloadCallbacks: PreloadCallbacks
authInterrupts: boolean
MetadataOutlet: ComponentType<{ tree: LoaderTree }> MetadataOutlet: ComponentType<{ tree: LoaderTree }>
isPrerendering: boolean isPrerendering: boolean
hintTree: PrefetchHints | null hintTree: PrefetchHints | null
...@@ -134,7 +133,6 @@ async function createComponentTreeInternal( ...@@ -134,7 +133,6 @@ async function createComponentTreeInternal(
ctx, ctx,
missingSlots, missingSlots,
preloadCallbacks, preloadCallbacks,
authInterrupts,
MetadataOutlet, MetadataOutlet,
isPrerendering, isPrerendering,
hintTree, hintTree,
...@@ -149,7 +147,6 @@ async function createComponentTreeInternal( ...@@ -149,7 +147,6 @@ async function createComponentTreeInternal(
ctx: AppRenderContext ctx: AppRenderContext
missingSlots?: Set<string> missingSlots?: Set<string>
preloadCallbacks: PreloadCallbacks preloadCallbacks: PreloadCallbacks
authInterrupts: boolean
MetadataOutlet: ComponentType<{ tree: LoaderTree }> | null MetadataOutlet: ComponentType<{ tree: LoaderTree }> | null
isPrerendering: boolean isPrerendering: boolean
hintTree: PrefetchHints | null hintTree: PrefetchHints | null
...@@ -279,27 +276,25 @@ async function createComponentTreeInternal( ...@@ -279,27 +276,25 @@ async function createComponentTreeInternal(
}) })
: [] : []
const [Forbidden, forbiddenStyles] = const [Forbidden, forbiddenStyles] = forbidden
authInterrupts && forbidden ? await createComponentStylesAndScripts({
? await createComponentStylesAndScripts({ ctx,
ctx, filePath: forbidden[1],
filePath: forbidden[1], getComponent: forbidden[0],
getComponent: forbidden[0], injectedCSS: injectedCSSWithCurrentLayout,
injectedCSS: injectedCSSWithCurrentLayout, injectedJS: injectedJSWithCurrentLayout,
injectedJS: injectedJSWithCurrentLayout, })
}) : []
: []
const [Unauthorized, unauthorizedStyles] = const [Unauthorized, unauthorizedStyles] = unauthorized
authInterrupts && unauthorized ? await createComponentStylesAndScripts({
? await createComponentStylesAndScripts({ ctx,
ctx, filePath: unauthorized[1],
filePath: unauthorized[1], getComponent: unauthorized[0],
getComponent: unauthorized[0], injectedCSS: injectedCSSWithCurrentLayout,
injectedCSS: injectedCSSWithCurrentLayout, injectedJS: injectedJSWithCurrentLayout,
injectedJS: injectedJSWithCurrentLayout, })
}) : []
: []
let dynamic = layoutOrPageMod?.dynamic let dynamic = layoutOrPageMod?.dynamic
...@@ -622,7 +617,6 @@ async function createComponentTreeInternal( ...@@ -622,7 +617,6 @@ async function createComponentTreeInternal(
ctx, ctx,
missingSlots, missingSlots,
preloadCallbacks, preloadCallbacks,
authInterrupts,
MetadataOutlet: MetadataOutlet:
experimental.parallelRouteMetadata || isChildrenRouteKey experimental.parallelRouteMetadata || isChildrenRouteKey
? MetadataOutlet ? MetadataOutlet
......
...@@ -171,7 +171,6 @@ export interface RenderOptsPartial { ...@@ -171,7 +171,6 @@ export interface RenderOptsPartial {
parallelRouteMetadata: boolean parallelRouteMetadata: boolean
inlineCss: boolean inlineCss: boolean
prefetchInlining: PrefetchInliningConfig prefetchInlining: PrefetchInliningConfig
authInterrupts: boolean
reactBrowserBailout: boolean reactBrowserBailout: boolean
serverComponentsHmrCancellation?: boolean serverComponentsHmrCancellation?: boolean
useCacheTimeout: number useCacheTimeout: number
......
...@@ -266,7 +266,6 @@ export async function walkTreeWithFlightRouterState({ ...@@ -266,7 +266,6 @@ export async function walkTreeWithFlightRouterState({
// This is intentionally not "rootLayoutIncludedAtThisLevelOrAbove" as createComponentTree starts at the current level and does a check for "rootLayoutAtThisLevel" too. // This is intentionally not "rootLayoutIncludedAtThisLevelOrAbove" as createComponentTree starts at the current level and does a check for "rootLayoutAtThisLevel" too.
rootLayoutIncluded, rootLayoutIncluded,
preloadCallbacks, preloadCallbacks,
authInterrupts: experimental.authInterrupts,
MetadataOutlet, MetadataOutlet,
isPrerendering: false, isPrerendering: false,
hintTree, hintTree,
...@@ -397,10 +396,7 @@ export async function createFullTreeForNavigation({ ...@@ -397,10 +396,7 @@ export async function createFullTreeForNavigation({
preloadCallbacks: PreloadCallbacks preloadCallbacks: PreloadCallbacks
MetadataOutlet: React.ComponentType<{ tree: LoaderTree }> MetadataOutlet: React.ComponentType<{ tree: LoaderTree }>
}): Promise<NavigationResponseTree> { }): Promise<NavigationResponseTree> {
const { const { pagePath } = ctx
renderOpts: { experimental },
pagePath,
} = ctx
const hintTreeForInitialRender = const hintTreeForInitialRender =
ctx.renderOpts.prefetchHints?.[pagePath] ?? null ctx.renderOpts.prefetchHints?.[pagePath] ?? null
...@@ -416,7 +412,6 @@ export async function createFullTreeForNavigation({ ...@@ -416,7 +412,6 @@ export async function createFullTreeForNavigation({
injectedFontPreloadTags, injectedFontPreloadTags,
rootLayoutIncluded: false, rootLayoutIncluded: false,
preloadCallbacks, preloadCallbacks,
authInterrupts: experimental.authInterrupts,
MetadataOutlet, MetadataOutlet,
isPrerendering: false, isPrerendering: false,
hintTree: hintTreeForInitialRender, hintTree: hintTreeForInitialRender,
......
...@@ -41,10 +41,7 @@ export type WorkStoreContext = { ...@@ -41,10 +41,7 @@ export type WorkStoreContext = {
pendingWaitUntil?: Promise<any> pendingWaitUntil?: Promise<any>
experimental: Pick< experimental: Pick<
RenderOpts['experimental'], RenderOpts['experimental'],
| 'isRoutePPREnabled' 'isRoutePPREnabled' | 'useCacheTimeout' | 'durableUseCacheEntries'
| 'authInterrupts'
| 'useCacheTimeout'
| 'durableUseCacheEntries'
> >
/** /**
......
...@@ -627,7 +627,6 @@ export default abstract class Server< ...@@ -627,7 +627,6 @@ export default abstract class Server<
inlineCss: this.nextConfig.experimental.inlineCss ?? false, inlineCss: this.nextConfig.experimental.inlineCss ?? false,
prefetchInlining: prefetchInlining:
this.nextConfig.experimental.prefetchInlining ?? false, this.nextConfig.experimental.prefetchInlining ?? false,
authInterrupts: !!this.nextConfig.experimental.authInterrupts,
reactBrowserBailout: reactBrowserBailout:
this.nextConfig.experimental.reactBrowserBailout ?? false, this.nextConfig.experimental.reactBrowserBailout ?? false,
serverComponentsHmrCancellation: serverComponentsHmrCancellation:
......
...@@ -1462,9 +1462,9 @@ export interface ExperimentalConfig { ...@@ -1462,9 +1462,9 @@ export interface ExperimentalConfig {
*/ */
inlineCss?: boolean inlineCss?: boolean
// TODO: Remove this config when the API is stable.
/** /**
* This config allows you to enable the experimental navigation API `forbidden` and `unauthorized`. * @deprecated `forbidden()` and `unauthorized()` are available by default.
* This option has no effect and can be removed.
*/ */
authInterrupts?: boolean authInterrupts?: boolean
...@@ -2456,7 +2456,6 @@ export const defaultConfig = Object.freeze({ ...@@ -2456,7 +2456,6 @@ export const defaultConfig = Object.freeze({
parallelServerCompiles: false, parallelServerCompiles: false,
parallelServerBuildTraces: false, parallelServerBuildTraces: false,
ppr: false, ppr: false,
authInterrupts: false,
webpackBuildWorker: undefined, webpackBuildWorker: undefined,
webpackMemoryOptimizations: false, webpackMemoryOptimizations: false,
optimizeServerReact: true, optimizeServerReact: true,
...@@ -2576,7 +2575,6 @@ export interface NextConfigRuntime { ...@@ -2576,7 +2575,6 @@ export interface NextConfigRuntime {
| 'parallelRouteMetadata' | 'parallelRouteMetadata'
| 'inlineCss' | 'inlineCss'
| 'prefetchInlining' | 'prefetchInlining'
| 'authInterrupts'
| 'reactBrowserBailout' | 'reactBrowserBailout'
| 'useCacheTimeout' | 'useCacheTimeout'
| 'durableUseCacheEntries' | 'durableUseCacheEntries'
...@@ -2648,7 +2646,6 @@ export function getNextConfigRuntime( ...@@ -2648,7 +2646,6 @@ export function getNextConfigRuntime(
parallelRouteMetadata: ex.parallelRouteMetadata, parallelRouteMetadata: ex.parallelRouteMetadata,
inlineCss: ex.inlineCss, inlineCss: ex.inlineCss,
prefetchInlining: ex.prefetchInlining, prefetchInlining: ex.prefetchInlining,
authInterrupts: ex.authInterrupts,
reactBrowserBailout: ex.reactBrowserBailout, reactBrowserBailout: ex.reactBrowserBailout,
useCacheTimeout: ex.useCacheTimeout, useCacheTimeout: ex.useCacheTimeout,
durableUseCacheEntries: ex.durableUseCacheEntries, durableUseCacheEntries: ex.durableUseCacheEntries,
......
...@@ -245,6 +245,13 @@ function checkDeprecations( ...@@ -245,6 +245,13 @@ function checkDeprecations(
silent silent
) )
warnOptionHasBeenDeprecated(
userConfig,
'experimental.authInterrupts',
`\`experimental.authInterrupts\` is no longer needed, because \`forbidden\` and \`unauthorized\` are available by default. You can remove it from ${configFileName}.`,
silent
)
warnOptionHasBeenDeprecated( warnOptionHasBeenDeprecated(
userConfig, userConfig,
'eslint', 'eslint',
......
...@@ -766,7 +766,6 @@ export default class DevServer extends Server { ...@@ -766,7 +766,6 @@ export default class DevServer extends Server {
nextConfigOutput: this.nextConfig.output, nextConfigOutput: this.nextConfig.output,
buildId: this.buildId, buildId: this.buildId,
deploymentId: this.deploymentId, deploymentId: this.deploymentId,
authInterrupts: Boolean(this.nextConfig.experimental.authInterrupts),
useCacheTimeout: this.nextConfig.experimental.useCacheTimeout, useCacheTimeout: this.nextConfig.experimental.useCacheTimeout,
durableUseCacheEntries: Boolean( durableUseCacheEntries: Boolean(
this.nextConfig.experimental.durableUseCacheEntries this.nextConfig.experimental.durableUseCacheEntries
......
...@@ -53,7 +53,6 @@ export async function loadStaticPaths({ ...@@ -53,7 +53,6 @@ export async function loadStaticPaths({
nextConfigOutput, nextConfigOutput,
buildId, buildId,
deploymentId, deploymentId,
authInterrupts,
useCacheTimeout, useCacheTimeout,
durableUseCacheEntries, durableUseCacheEntries,
staticPageGenerationTimeout, staticPageGenerationTimeout,
...@@ -78,7 +77,6 @@ export async function loadStaticPaths({ ...@@ -78,7 +77,6 @@ export async function loadStaticPaths({
nextConfigOutput: 'standalone' | 'export' | undefined nextConfigOutput: 'standalone' | 'export' | undefined
buildId: string buildId: string
deploymentId: string deploymentId: string
authInterrupts: boolean
useCacheTimeout: number useCacheTimeout: number
durableUseCacheEntries: boolean durableUseCacheEntries: boolean
staticPageGenerationTimeout: number staticPageGenerationTimeout: number
...@@ -161,7 +159,6 @@ export async function loadStaticPaths({ ...@@ -161,7 +159,6 @@ export async function loadStaticPaths({
isEnsureStaticPage, isEnsureStaticPage,
buildId, buildId,
deploymentId, deploymentId,
authInterrupts,
useCacheTimeout, useCacheTimeout,
durableUseCacheEntries, durableUseCacheEntries,
staticPageGenerationTimeout, staticPageGenerationTimeout,
......
...@@ -334,8 +334,6 @@ export async function adapter( ...@@ -334,8 +334,6 @@ export async function adapter(
validationLevel: 'warning', validationLevel: 'warning',
experimental: { experimental: {
isRoutePPREnabled: false, isRoutePPREnabled: false,
authInterrupts:
!!params.request.nextConfig?.experimental?.authInterrupts,
// Proxy doesn't fill Cache Components entries, so this value // Proxy doesn't fill Cache Components entries, so this value
// is never read. 0 is a sentinel: if something ever reads it, // is never read. 0 is a sentinel: if something ever reads it,
// the cache fill will time out immediately and surface the // the cache fill will time out immediately and surface the
......
...@@ -127,7 +127,6 @@ export class EdgeRouteModuleWrapper { ...@@ -127,7 +127,6 @@ export class EdgeRouteModuleWrapper {
// TODO: Remove validationLevel and other global config from renderOpts // TODO: Remove validationLevel and other global config from renderOpts
validationLevel: 'warning', validationLevel: 'warning',
experimental: { experimental: {
authInterrupts: !!process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS,
// Edge runtime doesn't support Cache Components, so this value is // Edge runtime doesn't support Cache Components, so this value is
// never read. 0 is a sentinel: if something ever reads it, the cache // never read. 0 is a sentinel: if something ever reads it, the cache
// fill will time out immediately and surface the bug. // fill will time out immediately and surface the bug.
......
...@@ -23,7 +23,7 @@ export interface RequestData { ...@@ -23,7 +23,7 @@ export interface RequestData {
trailingSlash?: boolean trailingSlash?: boolean
experimental?: Pick< experimental?: Pick<
ExperimentalConfig, ExperimentalConfig,
'cacheLife' | 'authInterrupts' | 'clientParamParsingOrigins' 'cacheLife' | 'clientParamParsingOrigins'
> >
} }
page?: { page?: {
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
*/ */
const nextConfig = { const nextConfig = {
experimental: { experimental: {
authInterrupts: true,
globalNotFound: true, globalNotFound: true,
}, },
} }
......
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
experimental: {
authInterrupts: true,
},
}
module.exports = nextConfig
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
const nextConfig = { const nextConfig = {
cacheComponents: true, cacheComponents: true,
experimental: { experimental: {
authInterrupts: true,
instantInsights: { instantInsights: {
validationLevel: 'manual-warning', validationLevel: 'manual-warning',
}, },
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
*/ */
const nextConfig = { const nextConfig = {
experimental: { experimental: {
authInterrupts: true,
explicitParallelRouteChildren: true, explicitParallelRouteChildren: true,
}, },
} }
......
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
experimental: {
authInterrupts: true,
},
}
module.exports = nextConfig
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
experimental: {
authInterrupts: true,
},
}
module.exports = nextConfig
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
experimental: {
authInterrupts: true,
},
}
module.exports = nextConfig
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
experimental: {
authInterrupts: true,
},
}
module.exports = nextConfig
/** @type {import('next').NextConfig} */
module.exports = {
experimental: {
authInterrupts: true,
},
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment