{"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/0eb377541648e63402a47b38fee00a8d0ce8f8f1/packages/next/src/client/components/forbidden.ts#L6-L33","documentation":"Feature gate on the forbidden() interrupt: calling it requires experimental.authInterrupts to be enabled in next.config because the auth-interrupt rendering flow is experimental. The throw fires when the function is invoked in a project without that flag set.","triggerScenarios":"forbidden() is called without enabling experimental.authInterrupts.","commonSituations":"Using the forbidden() API in app router code while the authInterrupts flag is off in next.config.","solutions":["Enable experimental.authInterrupts in next.config.js before calling forbidden(), or remove the forbidden() call."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0eb377541648e63402a47b38fee00a8d0ce8f8f1","analyzedAt":"2026-08-19T02:10:13.922Z","contentChangedAt":"2026-08-19T02:10:13.922Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}