修复ProfilePage:fetch改为apiClient,修复修改密码401错误
This commit is contained in:
@@ -3,6 +3,7 @@ import { Card, Typography, Form, Input, Button, Avatar, Space, Upload, message,
|
||||
import { UserOutlined, LockOutlined, PhoneOutlined, MailOutlined, UploadOutlined } from '@ant-design/icons';
|
||||
import { useAuthStore } from '../store/authStore';
|
||||
import useFormDraft from '../hooks/useFormDraft';
|
||||
import apiClient from '../utils/request';
|
||||
|
||||
const { Title, Paragraph } = Typography;
|
||||
|
||||
@@ -78,21 +79,14 @@ const ProfilePage: React.FC = () => {
|
||||
const values = await form.validateFields();
|
||||
setLoading(true);
|
||||
|
||||
// 调用API更新用户信息
|
||||
const response = await fetch(`/api/users/${user?.id}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
...values,
|
||||
avatar: avatarUrl,
|
||||
passport: passportUrl,
|
||||
driverLicense: driverLicenseUrl
|
||||
})
|
||||
const response = await apiClient.put(`/users/${user?.id}`, {
|
||||
...values,
|
||||
avatar: avatarUrl,
|
||||
passport: passportUrl,
|
||||
driverLicense: driverLicenseUrl
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
const data = response.data;
|
||||
if (data.success) {
|
||||
message.success('个人信息已更新');
|
||||
// 更新authStore中的用户信息
|
||||
@@ -121,19 +115,12 @@ const ProfilePage: React.FC = () => {
|
||||
try {
|
||||
const values = await passwordForm.validateFields();
|
||||
|
||||
// 调用API更新密码
|
||||
const response = await fetch(`/api/users/${user?.id}/password`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
currentPassword: values.currentPassword,
|
||||
newPassword: values.newPassword
|
||||
})
|
||||
const response = await apiClient.put(`/users/${user?.id}/password`, {
|
||||
currentPassword: values.currentPassword,
|
||||
newPassword: values.newPassword
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
const data = response.data;
|
||||
if (data.success) {
|
||||
message.success('密码已更新');
|
||||
setPasswordModalVisible(false);
|
||||
|
||||
Reference in New Issue
Block a user