27 lines
842 B
JavaScript
27 lines
842 B
JavaScript
import axios from "axios";
|
|
import CONFIG from "@/core/config.js";
|
|
|
|
const changeUserPassword = async (userId, newPasswordData) => {
|
|
try {
|
|
const token = localStorage.getItem("access_token");
|
|
const response = await axios.patch(
|
|
`${CONFIG.BASE_URL}/users/${userId}/password`,
|
|
newPasswordData,
|
|
{
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
},
|
|
}
|
|
);
|
|
return response.data;
|
|
} catch (error) {
|
|
if (error.response?.status === 400) {
|
|
throw new Error(error.response.data.detail);
|
|
} else if (error.response?.status === 403) {
|
|
throw new Error("Доступ запрещён (403)");
|
|
}
|
|
throw new Error(error.message);
|
|
}
|
|
};
|
|
|
|
export default changeUserPassword; |