fix(mining-admin-web): 适配后端API响应格式
后端返回格式为 { success, data: {...} },
修改 login 和 getProfile 解析 response.data.data
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
25ad627377
commit
e28fe56489
|
|
@ -28,8 +28,10 @@ export const login = createAsyncThunk(
|
||||||
async ({ username, password }: { username: string; password: string }, { rejectWithValue }) => {
|
async ({ username, password }: { username: string; password: string }, { rejectWithValue }) => {
|
||||||
try {
|
try {
|
||||||
const response = await authApi.login(username, password);
|
const response = await authApi.login(username, password);
|
||||||
localStorage.setItem('admin_token', response.data.accessToken);
|
// 后端返回格式: { success, data: { token, admin } }
|
||||||
return response.data;
|
const { token, admin } = response.data.data;
|
||||||
|
localStorage.setItem('admin_token', token);
|
||||||
|
return { accessToken: token, admin };
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return rejectWithValue(error.response?.data?.error?.message?.[0] || 'Login failed');
|
return rejectWithValue(error.response?.data?.error?.message?.[0] || 'Login failed');
|
||||||
}
|
}
|
||||||
|
|
@ -43,7 +45,8 @@ export const logout = createAsyncThunk('auth/logout', async () => {
|
||||||
export const getProfile = createAsyncThunk('auth/getProfile', async (_, { rejectWithValue }) => {
|
export const getProfile = createAsyncThunk('auth/getProfile', async (_, { rejectWithValue }) => {
|
||||||
try {
|
try {
|
||||||
const response = await authApi.getProfile();
|
const response = await authApi.getProfile();
|
||||||
return response.data;
|
// 后端返回格式: { success, data: { id, username, role } }
|
||||||
|
return response.data.data;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return rejectWithValue(error.response?.data?.error?.message?.[0] || 'Failed to get profile');
|
return rejectWithValue(error.response?.data?.error?.message?.[0] || 'Failed to get profile');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue