Closed zhangwei900808 closed 1 year ago
refreshToken method have a problem
Not setting "auth.accessToken" cookie. Response has finished.
You should set cookie before res.send()
Not setting "auth.refreshToken" cookie. Response has finished.
You should set cookie before res.send()
authSlice.js
// 使用refresh token 获取 access token
export const refreshToken = createAsyncThunk('auth/refreshToken', async (params, thunkAPI) => {
try {
const {refreshToken} = thunkAPI.getState().auth;
if (refreshToken) {
console.log('==== refreshToken ====', refreshToken)
delete axios.defaults.headers.Authorization;
const response = await axios.post('/account/info/refreshToken', {
refreshToken
});
const resdata = response.data;
if (resdata.status === 0 && resdata.data.access_token) {
return {
accessToken: resdata.data.access_token,
refreshToken: resdata.data.refresh_token,
isLogin: true,
isExpired: false
};
} else {
return thunkAPI.rejectWithValue({errorMsg: "获取access token失败"});
}
} else {
return thunkAPI.rejectWithValue({errorMsg: "no refreshToken"});
}
} catch (error) {
return thunkAPI.rejectWithValue({errorMsg: error.message});
}
});
[refreshToken.fulfilled]: (state, action) => {
if (action.payload) {
state.accessToken = action.payload.accessToken;
state.refreshToken = action.payload.refreshToken;
state.isLogin = action.payload.isLogin;
state.isExpired = action.payload.isExpired;
}
},
[refreshToken.rejected]: (state, action) => {
state.accessToken = null;
state.refreshToken = null;
state.me = null;
state.isLogin = false;
state.isExpired = true;
},
Closing this as stale
store.js
axiosMiddleware.js
look at
console.log('failedRequest=', store.getState().auth)
sometime I can get the auth state ,but sometime I cant get it why???