Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return ({ dispatch, getState }) => {
const rsaaMiddleware = apiMiddleware({dispatch, getState})
return (next) => (action) => {
const nextCheckPostoned = (nextAction) => {
// Run postponed actions after token refresh
if (nextAction.type === TOKEN_RECEIVED) {
next(nextAction);
postponedRSAAs.forEach((postponed) => {
rsaaMiddleware(next)(postponed)
})
postponedRSAAs = []
} else {
next(nextAction)
}
}
if(isRSAA(action)) {
return ({ dispatch, getState }) => {
const rsaaMiddleware = apiMiddleware({dispatch, getState});
return (next) => (action) => {
const nextCheckPostoned = (nextAction) => {
// Run postponed actions after token refresh
if (nextAction.type === REFRESH_TOKEN_SUCCESS) {
next(nextAction);
postponedRSAAs.forEach((postponed) => {
rsaaMiddleware(next)(postponed);
});
postponedRSAAs = [];
} else {
next(nextAction);
}
};
if(isRSAA(action)) {
return ({ dispatch, getState }) => {
const rsaaMiddleware = apiMiddleware({ dispatch, getState });
return processNextAction(postponedRSAAs, rsaaMiddleware, getState);
};
}
return ({ dispatch, getState }) => {
const rsaaMiddleware = apiMiddleware({ dispatch, getState });
return processNextAction(postponedRSAAs, rsaaMiddleware);
};
}
case 'TRACKS':
schema = arrayOf(trackSchema)
break
case 'WEBSITE':
schema = websiteSchema
break
case 'WEBSITES':
schema = arrayOf(websiteSchema)
break
default:
schema = null
}
return getJSON(res).then(json => normalize(json, schema))
}
}
return apiMiddleware(store)(next)(action)
}
}
return ({ dispatch, getState }) => {
const rsaaMiddleware = apiMiddleware({ dispatch, getState });
return processNextAction(postponedRSAAs, rsaaMiddleware, getState);
};
}