0
我想讓一些中間件刷新我的JWT,如果它已經過期了。目前,我有這個中間件:Redux中間件內部的函數不能正常工作
import { isTokenExpired, refreshToken } from '../modules/auth/auth.service'
export const jwt = store => next => action => {
if (typeof action === 'function') {
console.log("Middleware triggered:", action);
var theState = store.getState();
if (theState.auth && theState.auth.authToken && isTokenExpired(theState.auth.authToken)) {
console.log('This is logging')
//this function is not being called
refreshToken(theState.auth.refreshToken);
}
}
return next(action)
}
我想調用將啓動過程中的refreshToken()函數,但即便如此,目前爲止refreshToken內的console.log()不叫:
export const refreshToken = (refreshToken) => dispatch => {
console.log('Not logging')
}
此外,refreshToken函數在刷新令牌時將會異步。我正在考慮在減速器中設置「REFRESH_TOKEN_PENDING」類型,一旦收到響應,向減速器發送「REFRESH_TOKEN_SUCCESS」。這對中間件來說可能嗎?
感謝