Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): cleanup error.mdx #11657

Merged
merged 5 commits into from
Aug 28, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions docs/pages/guides/pages/error.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,30 @@ import { Screenshot } from "@/components/Screenshot"

Auth.js can be configured to display a custom error page when something goes wrong during the user authentication flow (sign in, sign out, etc..).

Using the [example app](https://github.com/nextauthjs/next-auth-example), let's build a simple custom error page:
In order to override Auth.js's `/api/auth/error` page we have to define our custom page in the AuthConfig:

<Code>
<Code.Next>

```tsx filename="app/error/page.tsx"
import { signIn } from "../auth.ts"
```tsx filename="src/auth.ts"
ndom91 marked this conversation as resolved.
Show resolved Hide resolved
const authConfig: NextAuthConfig = {
...
pages: {
error: "/error",
}
...
};
```

</Code.Next>
</Code>

Using the [example app](https://github.com/nextauthjs/next-auth-example), let's build a simple custom error page by creating `app/error/page.tsx`

<Code>
<Code.Next>

```tsx filename="app/error/page.tsx"
export default function AuthErrorPage() {
return <>Oops</>
}
Expand All @@ -38,7 +54,7 @@ So now we can update our custom error page with it:
```tsx filename="app/error/page.tsx"
"use client"

import { useParams, useSearchParams } from "next/navigation"
import { useSearchParams } from "next/navigation"

enum Error {
Configuration = "Configuration",
Expand All @@ -60,8 +76,7 @@ export default function AuthErrorPage() {

return (
<div className="flex flex-col items-center justify-center w-full h-screen">
<a
href="#"
<div
className="block max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700 text-center"
>
<h5 className="mb-2 text-xl font-bold tracking-tight text-gray-900 dark:text-white flex flex-row justify-center items-center gap-2">
Expand All @@ -70,8 +85,7 @@ export default function AuthErrorPage() {
<div className="font-normal text-gray-700 dark:text-gray-400">
{errorMap[error] || "Please contact us if this error persists."}
</div>
</a>
<div></div>
</div>
</div>
)
}
Expand Down
Loading