-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add forbidden and unauthorized APIs (#72785)
- Loading branch information
Showing
77 changed files
with
997 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { HTTPAccessErrorFallback } from './http-access-fallback/error-fallback' | ||
|
||
export default function Forbidden() { | ||
return ( | ||
<HTTPAccessErrorFallback | ||
status={403} | ||
message="This page could not be accessed." | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
HTTP_ERROR_FALLBACK_ERROR_CODE, | ||
type HTTPAccessFallbackError, | ||
} 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) | ||
* within a route segment as well as inject a tag. | ||
* | ||
* `forbidden()` can be used in | ||
* [Server Components](https://nextjs.org/docs/app/building-your-application/rendering/server-components), | ||
* [Route Handlers](https://nextjs.org/docs/app/building-your-application/routing/route-handlers), and | ||
* [Server Actions](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations). | ||
* | ||
* Read more: [Next.js Docs: `forbidden`](https://nextjs.org/docs/app/api-reference/functions/forbidden) | ||
*/ | ||
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.` | ||
) | ||
} | ||
|
||
// eslint-disable-next-line no-throw-literal | ||
const error = new Error( | ||
HTTP_ERROR_FALLBACK_ERROR_CODE | ||
) as HTTPAccessFallbackError | ||
;(error as HTTPAccessFallbackError).digest = | ||
`${HTTP_ERROR_FALLBACK_ERROR_CODE};403` | ||
throw error | ||
} |
Oops, something went wrong.