From e28fe56489eda2c0ee706c7653aa84d384895617 Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 11 Jan 2026 01:05:55 -0800 Subject: [PATCH] =?UTF-8?q?fix(mining-admin-web):=20=E9=80=82=E9=85=8D?= =?UTF-8?q?=E5=90=8E=E7=AB=AFAPI=E5=93=8D=E5=BA=94=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 后端返回格式为 { success, data: {...} }, 修改 login 和 getProfile 解析 response.data.data Co-Authored-By: Claude Opus 4.5 --- frontend/mining-admin-web/src/store/slices/auth.slice.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/mining-admin-web/src/store/slices/auth.slice.ts b/frontend/mining-admin-web/src/store/slices/auth.slice.ts index b3a1b10a..504105c0 100644 --- a/frontend/mining-admin-web/src/store/slices/auth.slice.ts +++ b/frontend/mining-admin-web/src/store/slices/auth.slice.ts @@ -28,8 +28,10 @@ export const login = createAsyncThunk( async ({ username, password }: { username: string; password: string }, { rejectWithValue }) => { try { const response = await authApi.login(username, password); - localStorage.setItem('admin_token', response.data.accessToken); - return response.data; + // 后端返回格式: { success, data: { token, admin } } + const { token, admin } = response.data.data; + localStorage.setItem('admin_token', token); + return { accessToken: token, admin }; } catch (error: any) { 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 }) => { try { const response = await authApi.getProfile(); - return response.data; + // 后端返回格式: { success, data: { id, username, role } } + return response.data.data; } catch (error: any) { return rejectWithValue(error.response?.data?.error?.message?.[0] || 'Failed to get profile'); }