Repository navigation
Add error pages #5
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,124 @@ | ||
| import { useMemo } from "react"; | ||
| import { useSearchParams } from "react-router"; | ||
| import { useLink } from "@refinedev/core"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { | ||
| Card, | ||
| CardContent, | ||
| CardDescription, | ||
| CardFooter, | ||
| CardHeader, | ||
| CardTitle, | ||
| } from "@/components/ui/card"; | ||
| import { Separator } from "@/components/ui/separator"; | ||
|
|
||
| const ERROR_MESSAGES: Record<string, { title: string; description: string }> = { | ||
| account_not_linked: { | ||
| title: "Account not linked", | ||
| description: | ||
| "This Google or GitHub account uses an email that already has a password login. Sign in with email/password first, or use the same method you used to register.", | ||
| }, | ||
| unable_to_link_account: { | ||
| title: "Could not link account", | ||
| description: | ||
| "We couldn't connect that social account to your user. Try again, or sign in with email and password.", | ||
| }, | ||
| oauth_provider_not_found: { | ||
| title: "Sign-in provider unavailable", | ||
| description: | ||
| "That login provider isn't configured. Try another method or contact support.", | ||
| }, | ||
| invalid_code: { | ||
| title: "Sign-in expired", | ||
| description: | ||
| "The login link expired or was already used. Please try signing in again.", | ||
| }, | ||
| state_mismatch: { | ||
| title: "Sign-in interrupted", | ||
| description: | ||
| "Something went wrong during the login redirect. Close extra tabs and try again.", | ||
| }, | ||
| access_denied: { | ||
| title: "Access denied", | ||
| description: | ||
| "You cancelled the sign-in request or didn't grant permission. Try again if that was a mistake.", | ||
| }, | ||
| email_not_verified: { | ||
| title: "Email not verified", | ||
| description: | ||
| "Your social account email must be verified before you can sign in this way.", | ||
| }, | ||
| }; | ||
|
|
||
| function resolveError(code: string | null, rawMessage: string | null) { | ||
| if (code && Object.prototype.hasOwnProperty.call(ERROR_MESSAGES, code)) { | ||
| return { code, ...ERROR_MESSAGES[code] }; | ||
| } | ||
|
|
||
| if (rawMessage) { | ||
| return { | ||
| code: code ?? "unknown", | ||
| title: "Sign-in failed", | ||
| description: rawMessage, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| code: code ?? "unknown", | ||
| title: "Something went wrong", | ||
| description: | ||
| "We couldn't complete sign-in. Please try again or return to the login page.", | ||
| }; | ||
| } | ||
|
|
||
| export default function AuthErrorPage() { | ||
| const [params] = useSearchParams(); | ||
| const Link = useLink(); | ||
|
|
||
| const error = useMemo(() => { | ||
| const code = | ||
| params.get("error") ?? | ||
| params.get("errorCode") ?? | ||
| params.get("code"); | ||
| const message = | ||
| params.get("error_description") ?? | ||
| params.get("message") ?? | ||
| params.get("errorDescription"); | ||
| return resolveError(code, message); | ||
| }, [params]); | ||
|
|
||
| return ( | ||
| <div className="flex min-h-svh flex-col items-center justify-center px-6 py-8"> | ||
| <Card className="w-full max-w-md p-8"> | ||
| <CardHeader className="px-0"> | ||
| <p className="text-sm font-medium text-destructive uppercase tracking-wide"> | ||
| Error | ||
| </p> | ||
| <CardTitle className="text-2xl">{error.title}</CardTitle> | ||
| <CardDescription className="text-base"> | ||
| {error.description} | ||
| </CardDescription> | ||
| </CardHeader> | ||
|
|
||
| <Separator /> | ||
|
|
||
| <CardContent className="px-0 pt-4"> | ||
| {error.code !== "unknown" && ( | ||
| <p className="rounded-md bg-muted px-3 py-2 text-xs text-muted-foreground font-mono"> | ||
| CODE: {error.code} | ||
| </p> | ||
| )} | ||
| </CardContent> | ||
|
|
||
| <CardFooter className="flex flex-col gap-3 px-0 sm:flex-row"> | ||
| <Button asChild className="w-full sm:w-auto"> | ||
| <Link to="/login">Back to login</Link> | ||
| </Button> | ||
| <Button asChild variant="outline" className="w-full sm:w-auto"> | ||
| <Link to="/">Go home</Link> | ||
| </Button> | ||
| </CardFooter> | ||
| </Card> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or 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,39 @@ | ||
| import { useLink } from "@refinedev/core"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { | ||
| Card, | ||
| CardContent, | ||
| CardDescription, | ||
| CardFooter, | ||
| CardHeader, | ||
| CardTitle, | ||
| } from "@/components/ui/card"; | ||
|
|
||
| export default function NotFoundPage() { | ||
| const Link = useLink(); | ||
|
|
||
| return ( | ||
| <div className="flex min-h-svh flex-col items-center justify-center px-6 py-8"> | ||
| <Card className="w-full max-w-md p-8 text-center"> | ||
| <CardHeader className="px-0"> | ||
| <p className="text-sm font-medium text-muted-foreground uppercase tracking-wide"> | ||
| 404 | ||
| </p> | ||
| <CardTitle className="text-2xl">Page not found</CardTitle> | ||
| <CardDescription className="text-base"> | ||
| That URL doesn't exist in this app. Check the link or go back home. | ||
| </CardDescription> | ||
| </CardHeader> | ||
| <CardContent className="px-0" /> | ||
| <CardFooter className="flex justify-center gap-3 px-0"> | ||
| <Button asChild> | ||
| <Link to="/">Go home</Link> | ||
| </Button> | ||
| <Button asChild variant="outline"> | ||
| <Link to="/login">Sign in</Link> | ||
| </Button> | ||
| </CardFooter> | ||
| </Card> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.