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