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:
parent
eb1ea81d8e
commit
7896be6062
|
|
@ -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,17 +59,20 @@ const authSlice = createSlice({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
extraReducers: (builder) => {
|
extraReducers: (builder) => {
|
||||||
builder.addCase(REHYDRATE, (state, action: PayloadAction<{ auth?: AuthState } | undefined>) => {
|
builder.addMatcher(
|
||||||
if (action.payload?.auth) {
|
(action): action is RehydrateAction => action.type === REHYDRATE,
|
||||||
const rehydratedAuth = action.payload.auth;
|
(state, action) => {
|
||||||
state.user = rehydratedAuth.user;
|
if (action.payload?.auth) {
|
||||||
state.token = rehydratedAuth.token;
|
const rehydratedAuth = action.payload.auth;
|
||||||
state.refreshToken = rehydratedAuth.refreshToken;
|
state.user = rehydratedAuth.user;
|
||||||
state.permissions = rehydratedAuth.permissions;
|
state.token = rehydratedAuth.token;
|
||||||
state.isAuthenticated = rehydratedAuth.isAuthenticated;
|
state.refreshToken = rehydratedAuth.refreshToken;
|
||||||
|
state.permissions = rehydratedAuth.permissions;
|
||||||
|
state.isAuthenticated = rehydratedAuth.isAuthenticated;
|
||||||
|
}
|
||||||
|
state.loading = false;
|
||||||
}
|
}
|
||||||
state.loading = false;
|
);
|
||||||
});
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue