feat: password reset by admin (#360)

This commit is contained in:
kimatata
2025-12-07 20:37:38 +09:00
committed by GitHub
parent 805c1f50b6
commit 2adb24dbaa
11 changed files with 244 additions and 9 deletions

View File

@@ -189,4 +189,43 @@ async function deleteAvatar(jwt: string) {
}
}
export { findUser, searchUsers, updateUserRole, updateUsername, updatePassword, uploadAvatar, deleteAvatar };
async function adminResetPassword(jwt: string, userId: number, newPassword: string) {
const updateData = {
newPassword,
};
const fetchOptions = {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${jwt}`,
},
body: JSON.stringify(updateData),
};
const url = `${apiServer}/users/${userId}/password`;
try {
const response = await fetch(url, fetchOptions);
if (!response.ok) {
const errorText = await response.text();
throw new Error(errorText || `HTTP error! Status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error: unknown) {
logError('Error admin resetting password:', error);
throw error;
}
}
export {
findUser,
searchUsers,
updateUserRole,
updateUsername,
updatePassword,
uploadAvatar,
deleteAvatar,
adminResetPassword,
};