final user account polish

This commit is contained in:
makearmy 2025-09-30 20:15:48 -04:00
parent d05dc3eab6
commit 0cbeca833f

View file

@ -24,7 +24,7 @@ export default function ProfileEditor({
const [first_name, setFirst] = useState("");
const [last_name, setLast] = useState("");
const [email, setEmail] = useState("");
const [location, setLocation] = useState("");
const [profileLocation, setProfileLocation] = useState(""); // renamed to avoid shadowing window.location
const [msg, setMsg] = useState<string | null>(null);
const [busy, setBusy] = useState(false);
const [loading, setLoading] = useState(!meProp);
@ -58,7 +58,7 @@ export default function ProfileEditor({
setFirst(me.first_name || "");
setLast(me.last_name || "");
setEmail(me.email || "");
setLocation(me.location || "");
setProfileLocation(me.location || "");
}, [me]);
const onSave = async () => {
@ -69,7 +69,7 @@ export default function ProfileEditor({
first_name: first_name.trim(),
last_name: last_name.trim(),
email: email.trim() || null, // allow clearing email
location: location.trim(),
location: profileLocation.trim(),
};
const r = await fetch("/api/account/profile", {
method: "PATCH",
@ -78,11 +78,17 @@ export default function ProfileEditor({
});
if (r.status === 428) {
// Need reauth for sensitive change (email)
location.assign(`/auth/sign-in?reauth=1&next=${encodeURIComponent(nextAccount + "#security")}`);
if (typeof window !== "undefined") {
window.location.assign(
`/auth/sign-in?reauth=1&next=${encodeURIComponent(nextAccount + "#security")}`
);
}
return;
}
if (r.status === 401) {
location.assign(`/auth/sign-in?reauth=1&next=${encodeURIComponent(nextAccount)}`);
if (typeof window !== "undefined") {
window.location.assign(`/auth/sign-in?reauth=1&next=${encodeURIComponent(nextAccount)}`);
}
return;
}
const j = await r.json().catch(() => ({}));
@ -139,8 +145,8 @@ export default function ProfileEditor({
<span className="opacity-60">Location</span>
<input
className="rounded-md border px-2 py-1"
value={location}
onChange={(e) => setLocation(e.target.value)}
value={profileLocation}
onChange={(e) => setProfileLocation(e.target.value)}
placeholder="City, Country"
/>
</label>