import { useState } from "react"; import { Link } from "wouter"; import { z } from "zod"; import Container from "@mui/material/Container"; import Alert from "@mui/material/Alert"; import { apiRequest, parse, organizationSchema } from "@/lib/api"; import { clearRecoveryToken, getRecoveryToken } from "@/lib/recovery-token"; import { usePlatform } from "@/lib/platform"; import { ActionForm, Field, Panel, readText, } from "@/components/WorkspaceTools"; import "./workspace.css"; export default function RecoveryPage({ reset = false }: { reset?: boolean }) { const { organization, clearSession } = usePlatform(); const [complete, setComplete] = useState(false); const token = getRecoveryToken(); return (

{reset ? "Reset Password" : "Account Recovery"}

{complete ? ( {reset ? "Your password was reset and previous sessions were invalidated." : "If the account is eligible, recovery instructions will be sent."}{" "} Return to sign-in ) : reset ? ( !token ? ( This reset link is missing or invalid. Request a new recovery link. ) : ( { const password = readText(data, "password"); if (password !== readText(data, "confirm")) throw new Error("Passwords do not match."); return { token, password }; }} submit={async (value) => { const body = z .object({ token: z.string().regex(/^[A-Za-z0-9_-]{43}$/), password: z.string().min(15).max(128), }) .strict() .parse(value); parse( z.null(), await apiRequest("/auth/recovery/reset", { method: "POST", body, }), ); clearRecoveryToken(); clearSession( "Password reset. Sign in with your new password.", ); setComplete(true); }} > ) ) : ( <> Recovery delivery requires the backend SMTP configuration. Acceptance does not confirm account existence or email delivery. ({ organizationId: readText(data, "organizationId"), email: readText(data, "email"), })} submit={async (value) => { const body = z .object({ organizationId: organizationSchema, email: z.string().email().max(254).toLowerCase(), }) .strict() .parse(value); parse( z.object({ message: z.string() }), await apiRequest("/auth/recovery/request", { method: "POST", body, }), ); setComplete(true); }} > )}
); }