1
0
Fork 0
fahrPool/web/app/passwort-aendern/page.tsx

70 lines
2.2 KiB
TypeScript

import { redirect } from "next/navigation";
import { createClient } from "@/lib/supabase/server";
import { MIN_PASSWORT_LAENGE, hatPasswortAenderPflicht } from "@/lib/auth/passwort";
import { aendereMeinPasswort } from "./actions";
import { Button } from "@/components/ui/Button";
import { Card } from "@/components/ui/Card";
import { Alert } from "@/components/ui/Alert";
import { FormField, FIELD_CLASSES } from "@/components/ui/FormField";
export default async function PasswortAendernPage({
searchParams,
}: {
searchParams: Promise<{ error?: string }>;
}) {
const supabase = await createClient();
const {
data: { user },
} = await supabase.auth.getUser();
if (!user) {
redirect("/login");
}
if (!hatPasswortAenderPflicht(user)) {
redirect("/");
}
const { error } = await searchParams;
return (
<div className="flex flex-1 items-center justify-center px-4 py-8">
<Card className="w-full max-w-sm">
<h1 className="mb-2 text-center text-xl font-semibold text-asphalt-grey">Neues Passwort festlegen</h1>
<p className="mb-6 text-center text-asphalt-grey">
Dein Passwort wurde vom Admin gesetzt. Bitte lege jetzt ein eigenes Passwort fest.
</p>
{error && (
<div className="mb-4">
<Alert>{error}</Alert>
</div>
)}
<form action={aendereMeinPasswort}>
<FormField label="Neues Passwort" htmlFor="neu">
<input
id="neu"
name="neu"
type="password"
required
minLength={MIN_PASSWORT_LAENGE}
autoComplete="new-password"
className={FIELD_CLASSES}
/>
</FormField>
<FormField label="Neues Passwort wiederholen" htmlFor="wiederholung">
<input
id="wiederholung"
name="wiederholung"
type="password"
required
minLength={MIN_PASSWORT_LAENGE}
autoComplete="new-password"
className={FIELD_CLASSES}
/>
</FormField>
<Button type="submit">Passwort speichern</Button>
</form>
</Card>
</div>
);
}