RTK Query를 적용하며 편리했던 속성 및 사용법
prepareHeaders: (headers) => {
const token = sessionStorage.getItem('accessToken');
if (token) {
headers.set('authorization', 'Bearer ' + token);
}
return headers;
},
transformResponse: (response: { data: MyKeywordsResponse }) => response.data,
const rtkQueryPromiseInterceptor: Middleware = () => (next) => (action) => {
const token = sessionStorage.getItem('accessToken');
if (isPending(action)) {
if (!token) {
abort();
}
}
if (isRejectedWithValue(action)) {
if ((token && action.payload.status === 401) || action.payload.status === 500) {
sessionStorage.clear();
window.location.assign('/');
}
}
return next(action);
};