feat: change email and password in settings
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user