{"record":{"id":"aa38e78784bd18bd","repo":"vercel/next.js","slug":"forbidden-is-experimental-and-only-allowed-to","errorCode":null,"errorMessage":"`forbidden()` is experimental and only allowed to be enabled when `experimental.authInterrupts` is enabled.","messagePattern":"`forbidden\\(\\)` is experimental and only allowed to be enabled when `experimental\\.authInterrupts` is enabled\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/client/components/forbidden.ts","lineNumber":24,"sourceCode":"// TODO: Add `forbidden` docs\n/**\n * @experimental\n * This function allows you to render the [forbidden.js file](https://nextjs.org/docs/app/api-reference/file-conventions/forbidden)\n * within a route segment as well as inject a tag.\n *\n * `forbidden()` can be used in\n * [Server Components](https://nextjs.org/docs/app/building-your-application/rendering/server-components),\n * [Route Handlers](https://nextjs.org/docs/app/building-your-application/routing/route-handlers), and\n * [Server Actions](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations).\n *\n * Read more: [Next.js Docs: `forbidden`](https://nextjs.org/docs/app/api-reference/functions/forbidden)\n */\n\nconst DIGEST = `${HTTP_ERROR_FALLBACK_ERROR_CODE};403`\n\nexport function forbidden(): never {\n  if (!process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS) {\n    throw new Error(\n      `\\`forbidden()\\` is experimental and only allowed to be enabled when \\`experimental.authInterrupts\\` is enabled.`\n    )\n  }\n\n  const error = new Error(DIGEST) as HTTPAccessFallbackError\n  ;(error as HTTPAccessFallbackError).digest = DIGEST\n  throw error\n}\n","sourceCodeStart":6,"sourceCodeEnd":33,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/client/components/forbidden.ts#L6-L33","documentation":"`forbidden()` is an experimental function that throws a 403 access-fallback error to render the `forbidden.js` boundary. It checks `process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS` and throws this configuration error if the flag is not set, because the underlying auth-interrupts feature must be explicitly enabled via `experimental.authInterrupts` in next.config.","triggerScenarios":"Calling `forbidden()` from `next/navigation` (or the internal forbidden module) in a Server Component, Route Handler, or Server Action without `experimental.authInterrupts: true` in next.config.js/ts.","commonSituations":"Following a tutorial or docs example that uses forbidden() without mentioning the required flag; upgrading Next.js and trying the new API without updating config; the flag name changed or the feature is not yet stable in your version.","solutions":["Enable the flag in next.config: `export default { experimental: { authInterrupts: true } }`.","If you don't want the experimental feature, remove the forbidden() call and use a manual redirect to a 403 page.","Restart the dev server after changing next.config so the env var is re-injected."],"exampleFix":"// next.config.ts\n// before — missing the flag\nimport type { NextConfig } from 'next'\nconst config: NextConfig = {}\nexport default config\n\n// after — enable authInterrupts\nimport type { NextConfig } from 'next'\nconst config: NextConfig = {\n  experimental: { authInterrupts: true },\n}\nexport default config","handlingStrategy":"validation","validationCode":"function isAuthInterruptsEnabled(): boolean {\n  return process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS === '1'\n}\nfunction safeForbidden(): void {\n  if (!isAuthInterruptsEnabled()) {\n    throw new Error('Enable experimental.authInterrupts in next.config before using forbidden()')\n  }\n  // call the real forbidden()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add experimental.authInterrupts to next.config before using forbidden() or unauthorized().","Restart the dev server after changing next.config so the flag env var is injected.","Check your Next.js version supports the authInterrupts flag before enabling it."],"tags":["experimental","auth","forbidden","config","auth-interrupts"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}