feat: change email and password in settings

This commit is contained in:
2026-01-28 21:52:17 +00:00
parent 696e2187f4
commit a3d4f09291
2 changed files with 237 additions and 57 deletions

View File

@@ -95,6 +95,33 @@ class ApiClient {
}
}
// Account (email & password changes via Better Auth)
async changePassword(currentPassword: string, newPassword: string): Promise<void> {
const response = await fetch(`${AUTH_BASE}/api/auth/change-password`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...this.authHeaders() },
credentials: 'include',
body: JSON.stringify({ currentPassword, newPassword }),
});
if (!response.ok) {
const error = await response.json().catch(() => ({ message: 'Failed to change password' }));
throw new Error(error.message || 'Failed to change password');
}
}
async changeEmail(newEmail: string): Promise<void> {
const response = await fetch(`${AUTH_BASE}/api/auth/change-email`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...this.authHeaders() },
credentials: 'include',
body: JSON.stringify({ newEmail }),
});
if (!response.ok) {
const error = await response.json().catch(() => ({ message: 'Failed to change email' }));
throw new Error(error.message || 'Failed to change email');
}
}
// Profile
async getProfile(): Promise<Profile> {
return this.fetch('/profile');