fix(admin-web): 修复 authSlice 的 REHYDRATE 类型错误

使用 addMatcher 替代 addCase 处理 REHYDRATE action

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-20 00:35:03 -08:00
parent eb1ea81d8e
commit 7896be6062
1 changed files with 20 additions and 11 deletions

View File

@ -1,4 +1,4 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { createSlice, PayloadAction, Action } from '@reduxjs/toolkit';
import { REHYDRATE } from 'redux-persist';
import type { User } from '@/types/user.types';
@ -11,6 +11,12 @@ interface AuthState {
loading: boolean;
}
interface RehydrateAction extends Action<typeof REHYDRATE> {
payload?: {
auth?: AuthState;
};
}
const initialState: AuthState = {
user: null,
token: null,
@ -53,17 +59,20 @@ const authSlice = createSlice({
},
},
extraReducers: (builder) => {
builder.addCase(REHYDRATE, (state, action: PayloadAction<{ auth?: AuthState } | undefined>) => {
if (action.payload?.auth) {
const rehydratedAuth = action.payload.auth;
state.user = rehydratedAuth.user;
state.token = rehydratedAuth.token;
state.refreshToken = rehydratedAuth.refreshToken;
state.permissions = rehydratedAuth.permissions;
state.isAuthenticated = rehydratedAuth.isAuthenticated;
builder.addMatcher(
(action): action is RehydrateAction => action.type === REHYDRATE,
(state, action) => {
if (action.payload?.auth) {
const rehydratedAuth = action.payload.auth;
state.user = rehydratedAuth.user;
state.token = rehydratedAuth.token;
state.refreshToken = rehydratedAuth.refreshToken;
state.permissions = rehydratedAuth.permissions;
state.isAuthenticated = rehydratedAuth.isAuthenticated;
}
state.loading = false;
}
state.loading = false;
});
);
},
});