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 { REHYDRATE } from 'redux-persist';
import type { User } from '@/types/user.types'; import type { User } from '@/types/user.types';
@ -11,6 +11,12 @@ interface AuthState {
loading: boolean; loading: boolean;
} }
interface RehydrateAction extends Action<typeof REHYDRATE> {
payload?: {
auth?: AuthState;
};
}
const initialState: AuthState = { const initialState: AuthState = {
user: null, user: null,
token: null, token: null,
@ -53,7 +59,9 @@ const authSlice = createSlice({
}, },
}, },
extraReducers: (builder) => { extraReducers: (builder) => {
builder.addCase(REHYDRATE, (state, action: PayloadAction<{ auth?: AuthState } | undefined>) => { builder.addMatcher(
(action): action is RehydrateAction => action.type === REHYDRATE,
(state, action) => {
if (action.payload?.auth) { if (action.payload?.auth) {
const rehydratedAuth = action.payload.auth; const rehydratedAuth = action.payload.auth;
state.user = rehydratedAuth.user; state.user = rehydratedAuth.user;
@ -63,7 +71,8 @@ const authSlice = createSlice({
state.isAuthenticated = rehydratedAuth.isAuthenticated; state.isAuthenticated = rehydratedAuth.isAuthenticated;
} }
state.loading = false; state.loading = false;
}); }
);
}, },
}); });