I want to add a middleware to all API calls with React RTK. To be specific I want to add the Firebase Performance Monitoring plugin to monitor the HTTP request: https://rnfirebase.io/perf/usage#http-request-tracing.
So how can I add a middleware just for the API calls?
This is our api (this is off course not the whole api but you get the poin):
export const api = createApi({
reducerPath: 'api',
baseQuery: fetchBaseQuery({
baseUrl: Config.API_ENDPOINT,
prepareHeaders: (headers, { getState }) => {
const token = (getState() as RootState).app.token
if (token) {
headers.set('Authorization', 'Bearer ' + token)
}
return headers
}
}),
tagTypes: ['AuthToken'],
endpoints: (builder) => ({
auth: builder.query<BaseResponse<AuthResult>, any>({
query: () => ({
url: '/auth/token',
method: 'POST',
responseHandler: (response) => response.json()
}),
providesTags: ['AuthToken'],
}),
}),
}),
})
Thanks in advance.