diff --git a/components/account/ProfileEditor.tsx b/components/account/ProfileEditor.tsx index fe2790eb..83c56b75 100644 --- a/components/account/ProfileEditor.tsx +++ b/components/account/ProfileEditor.tsx @@ -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(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({ Location setLocation(e.target.value)} + value={profileLocation} + onChange={(e) => setProfileLocation(e.target.value)} placeholder="City, Country" />