cleaner nullable name
All checks were successful
Deploy to Server / deploy (push) Successful in 33s

This commit is contained in:
2026-04-10 21:22:31 -05:00
parent 508b1e8169
commit 8d9066d229
2 changed files with 23 additions and 4 deletions

View File

@@ -8,7 +8,7 @@ import { useSession, signOut, updateUser } from '../lib/auth-client';
import { validatePhoneOrEmail } from '../lib/validators';
export function ProfileSettings() {
const { data: session } = useSession();
const { data: session, refetch: refetchSession } = useSession();
const [userName, setUserName] = useState('');
const [savingName, setSavingName] = useState(false);
const [nameSaved, setNameSaved] = useState(false);
@@ -48,11 +48,18 @@ export function ProfileSettings() {
setNameSaved(false);
const trimmed = userName.trim();
setSavingName(true);
const { error: err } = await updateUser({ name: trimmed });
const res = await fetch('/api/account/name', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({ name: trimmed || null }),
});
setSavingName(false);
if (err) {
setNameError(err.message || 'Failed to save name.');
if (!res.ok) {
const data = await res.json().catch(() => ({}));
setNameError(data.error || 'Failed to save name.');
} else {
await refetchSession();
setNameSaved(true);
setTimeout(() => setNameSaved(false), 3000);
}