|
| 1 | +"use client" |
| 2 | + |
| 3 | +import { Card, CardHeader, CardDescription, CardTitle, CardContent, CardFooter } from "@/components/ui/card" |
| 4 | +import { Button } from "@/components/ui/button" |
| 5 | +import { ArrowLeft, AlertCircle } from "lucide-react" |
| 6 | +import { useSearchParams } from "next/navigation" |
| 7 | +import { Suspense } from "react" |
| 8 | +import Link from "next/link" |
| 9 | +import { SourcebotLogo } from "@/app/components/sourcebotLogo" |
| 10 | +import { Footer } from "@/app/components/footer" |
| 11 | +import { SOURCEBOT_SUPPORT_EMAIL } from "@/lib/constants" |
| 12 | + |
| 13 | +// @see https://authjs.dev/guides/pages/error |
| 14 | +const ERROR_CONTENT: Record<string, { title: string; description: string }> = { |
| 15 | + Configuration: { |
| 16 | + title: "Server configuration error", |
| 17 | + description: "There is a problem with the server's authentication configuration. Please contact your administrator.", |
| 18 | + }, |
| 19 | + AccessDenied: { |
| 20 | + title: "Access denied", |
| 21 | + description: "You do not have permission to sign in.", |
| 22 | + }, |
| 23 | + Verification: { |
| 24 | + title: "This sign-in link has expired", |
| 25 | + description: "The code or link you used is no longer valid - it may have expired or already been used. Request a new one and try again.", |
| 26 | + }, |
| 27 | + Default: { |
| 28 | + title: "Unable to sign in", |
| 29 | + description: "Something went wrong while signing you in. Please try again.", |
| 30 | + }, |
| 31 | +} |
| 32 | + |
| 33 | +function ErrorPageContent() { |
| 34 | + const searchParams = useSearchParams() |
| 35 | + const error = searchParams.get("error") ?? "Default" |
| 36 | + const { title, description } = ERROR_CONTENT[error] ?? ERROR_CONTENT.Default |
| 37 | + |
| 38 | + return ( |
| 39 | + <div className="flex flex-col min-h-screen"> |
| 40 | + <div className="flex-1 flex flex-col items-center p-4 sm:p-12 w-full bg-backgroundSecondary"> |
| 41 | + <div className="w-full max-w-md"> |
| 42 | + <div className="flex justify-center mb-6"> |
| 43 | + <SourcebotLogo className="h-16" size="large" /> |
| 44 | + </div> |
| 45 | + <Card className="w-full"> |
| 46 | + <CardHeader className="space-y-3"> |
| 47 | + <div className="flex justify-center"> |
| 48 | + <div className="flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10"> |
| 49 | + <AlertCircle className="h-6 w-6 text-destructive" /> |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + <CardTitle className="text-2xl text-center">{title}</CardTitle> |
| 53 | + <CardDescription className="text-center"> |
| 54 | + {description} |
| 55 | + </CardDescription> |
| 56 | + </CardHeader> |
| 57 | + |
| 58 | + <CardContent> |
| 59 | + <Button asChild className="w-full"> |
| 60 | + <Link href="/login"> |
| 61 | + <ArrowLeft className="mr-2 h-4 w-4" /> |
| 62 | + Back to login |
| 63 | + </Link> |
| 64 | + </Button> |
| 65 | + </CardContent> |
| 66 | + |
| 67 | + <CardFooter className="pt-0"> |
| 68 | + <div className="w-full text-center text-sm text-muted-foreground"> |
| 69 | + <p> |
| 70 | + Having trouble?{" "} |
| 71 | + <a href={`mailto:${SOURCEBOT_SUPPORT_EMAIL}`} className="text-primary hover:underline"> |
| 72 | + Contact support |
| 73 | + </a> |
| 74 | + </p> |
| 75 | + </div> |
| 76 | + </CardFooter> |
| 77 | + </Card> |
| 78 | + </div> |
| 79 | + </div> |
| 80 | + <Footer /> |
| 81 | + </div> |
| 82 | + ) |
| 83 | +} |
| 84 | + |
| 85 | +function LoadingErrorPage() { |
| 86 | + return ( |
| 87 | + <div className="min-h-screen flex flex-col items-center justify-center p-4 bg-backgroundSecondary"> |
| 88 | + <div className="w-full max-w-md"> |
| 89 | + <div className="flex justify-center mb-6"> |
| 90 | + <SourcebotLogo className="h-16" size="large" /> |
| 91 | + </div> |
| 92 | + <Card className="w-full"> |
| 93 | + <CardHeader className="space-y-1"> |
| 94 | + <CardTitle className="text-2xl font-semibold text-center">Loading...</CardTitle> |
| 95 | + </CardHeader> |
| 96 | + </Card> |
| 97 | + </div> |
| 98 | + </div> |
| 99 | + ) |
| 100 | +} |
| 101 | + |
| 102 | +export default function AuthErrorPage() { |
| 103 | + return ( |
| 104 | + <Suspense fallback={<LoadingErrorPage />}> |
| 105 | + <ErrorPageContent /> |
| 106 | + </Suspense> |
| 107 | + ) |
| 108 | +} |
0 commit comments