Error boundary

This commit is contained in:
PxlLoewe
2025-03-26 14:04:15 -07:00
parent 9551202370
commit c8d91b684f
21 changed files with 414 additions and 298 deletions

View File

@@ -8,8 +8,10 @@ import { useForm } from "react-hook-form";
import { Toaster, toast } from "react-hot-toast";
import { z } from "zod";
import { Button } from "../../../_components/ui/Button";
import { useErrorBoundary } from "react-error-boundary";
export const Login = () => {
const { showBoundary } = useErrorBoundary();
const [isLoading, setIsLoading] = useState(false);
const searchParams = useSearchParams();
const schema = z.object({
@@ -28,22 +30,26 @@ export const Login = () => {
className="card-body"
onSubmit={form.handleSubmit(async () => {
setIsLoading(true);
const data = await signIn("credentials", {
redirect: false,
email: form.getValues("email"),
password: form.getValues("password"),
});
setIsLoading(false);
if (!data || data.error) {
toast.error("E-Mail / Passwort ist falsch!", {
style: {
background: "var(--color-base-100)",
color: "var(--color-base-content)",
},
try {
const data = await signIn("credentials", {
redirect: false,
email: form.getValues("email"),
password: form.getValues("password"),
});
return;
setIsLoading(false);
if (!data || data.error) {
toast.error("E-Mail / Passwort ist falsch!", {
style: {
background: "var(--color-base-100)",
color: "var(--color-base-content)",
},
});
return;
}
redirect(searchParams.get("redirect") || "/");
} catch (error) {
showBoundary(error);
}
redirect(searchParams.get("redirect") || "/");
})}
>
<div>
@@ -99,6 +105,11 @@ export const Login = () => {
className="grow"
/>
</label>
<span className="text-sm font-medium flex justify-end">
<Link href="/passwort-reset" className="link link-accent link-hover ">
Passwort vergessen?
</Link>
</span>
<div className="card-actions mt-6">
<Button
disabled={isLoading}