Private
Public Access
1
0

Fix account settings: add invalidateAll, robust error handling

- Add invalidateAll() after profile save so nav bar updates immediately
- Wrap all async handlers in try/finally to prevent stuck loading states
- Make form onsubmit handlers async to properly propagate errors

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Catherine Renelle
2026-02-26 19:31:02 -05:00
parent 1419300baa
commit 5f552a9883
+36 -25
View File
@@ -1,6 +1,7 @@
<script lang="ts">
import { api } from '$lib/utils/api.js';
import { toast } from '$lib/stores/toasts.svelte.js';
import { invalidateAll } from '$app/navigation';
let { data } = $props();
@@ -21,14 +22,18 @@
async function saveProfile() {
savingProfile = true;
const result = await api('/api/account', {
method: 'PATCH',
body: JSON.stringify({ name: name.trim(), email: email.trim() })
});
savingProfile = false;
try {
const result = await api('/api/account', {
method: 'PATCH',
body: JSON.stringify({ name: name.trim(), email: email.trim() })
});
if (result.ok) {
toast.success('Profile updated');
if (result.ok) {
toast.success('Profile updated');
await invalidateAll();
}
} finally {
savingProfile = false;
}
}
@@ -39,29 +44,35 @@
}
savingPassword = true;
const result = await api('/api/account', {
method: 'PATCH',
body: JSON.stringify({ currentPassword, newPassword })
});
savingPassword = false;
try {
const result = await api('/api/account', {
method: 'PATCH',
body: JSON.stringify({ currentPassword, newPassword })
});
if (result.ok) {
currentPassword = '';
newPassword = '';
confirmPassword = '';
sessionCount = 1; // only current session remains
toast.success('Password changed. Other sessions have been logged out.');
if (result.ok) {
currentPassword = '';
newPassword = '';
confirmPassword = '';
sessionCount = 1;
toast.success('Password changed. Other sessions have been logged out.');
}
} finally {
savingPassword = false;
}
}
async function revokeOtherSessions() {
revokingSessions = true;
const result = await api('/api/account', { method: 'DELETE' });
revokingSessions = false;
try {
const result = await api('/api/account', { method: 'DELETE' });
if (result.ok) {
sessionCount = 1;
toast.success(`Logged out of ${result.data.sessionsRevoked} other session(s)`);
if (result.ok) {
sessionCount = 1;
toast.success(`Logged out of ${result.data.sessionsRevoked} other session(s)`);
}
} finally {
revokingSessions = false;
}
}
</script>
@@ -77,7 +88,7 @@
<section class="mb-8">
<h2 class="text-lg font-semibold text-gray-800 dark:text-gray-200 mb-3">Profile</h2>
<div class="rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 p-4">
<form onsubmit={(e) => { e.preventDefault(); saveProfile(); }} class="space-y-3">
<form onsubmit={async (e) => { e.preventDefault(); await saveProfile(); }} class="space-y-3">
<div>
<label for="profile-name" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Name</label>
<input
@@ -113,7 +124,7 @@
<section class="mb-8">
<h2 class="text-lg font-semibold text-gray-800 dark:text-gray-200 mb-3">Change Password</h2>
<div class="rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 p-4">
<form onsubmit={(e) => { e.preventDefault(); changePassword(); }} class="space-y-3">
<form onsubmit={async (e) => { e.preventDefault(); await changePassword(); }} class="space-y-3">
<div>
<label for="current-password" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Current Password</label>
<input