I’m trying to invalidate tag on mutation of user update but invalidate tags not working, it try to run the invalidate tag function but did not refetch anything.
I was using the same implementation in one of the other projects it was working fine on that project but here its not working.
Here is the code .
Below is the api file where I have provided tags and invalidating them.
import { createApi } from "@reduxjs/toolkit/query/react";
import { baseQueryWithReauth } from "store/baseQuery";
export const authApi = createApi({
baseQuery: baseQueryWithReauth,
reducerPath: "authApi",
tagTypes: ['User'],
endpoints: (build) => ({
registration: build.mutation({
query(body) {
return {
url: `/rest-auth/registration/`,
method: "POST",
body
};
},
}),
login: build.mutation({
query(body) {
return {
url: `/rest-auth/login/`,
method: "POST",
body
};
},
}),
getUser: build.query({
query() {
return {
url: '/api/personas/patients/me/',
method: "GET"
};
},
transformResponse: (resp) => {
const { user, ...rest } = resp;
return { ...user, ...rest };
},
providesTags: ['User'],
}),
resetPasswordEmail: build.mutation({
query(body) {
return {
url: `/rest-auth/password/reset/`,
method: "POST",
body
};
},
}),
resetPassword: build.mutation({
query(body) {
return {
url: `/rest-auth/password/reset/confirm/`,
method: "POST",
body
};
},
}),
changePassword: build.mutation({
query(body) {
return {
url: `/rest-auth/password/change/`,
method: "POST",
body
};
},
}),
logout: build.mutation({
query(body) {
return {
url: `/rest-auth/logout/`,
method: "POST",
body
};
},
}),
updateProfile: build.mutation({
query({ body, id }) {
return {
url: `/api/personas/patients/${id}/`,
method: "PATCH",
body
};
},
invalidatesTags: ['User'],
}),
updateUser: build.mutation({
query({ body }) {
return {
url: `/rest-auth/user/`,
method: "PATCH",
body
};
},
invalidatesTags: ['User']
}),
}),
});
export const { useLoginMutation, useResetPasswordEmailMutation, useRegistrationMutation, useGetUserQuery, useResetPasswordMutation, useChangePasswordMutation, useLogoutMutation, useUpdateProfileMutation, useUpdateUserMutation } = authApi;
Here is the store setup for my project
import {
combineReducers,
configureStore,
} from "@reduxjs/toolkit";
import { authApi } from "apis/auth.api";
import userSlice from "slices/user.slice";
const combinedReducer = combineReducers({
[authApi.reducerPath]: authApi.reducer,
user: userSlice,
});
const rootReducer = (state, action) => {
return combinedReducer(state, action);
};
const store = configureStore({
reducer: rootReducer,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware().concat([
authApi.middleware,
]),
});
export default store;
versions:-
“@reduxjs/toolkit”: “^2.0.1”,
“react-redux”: “^9.0.4”,