I have written an axios interceptor where I want to add the idToken for a user to the headers on every api call.
axiosInstance.interceptors.request.use(
async (config: InternalAxiosRequestConfig<any>) => {
try {
config.headers.authorization = `Bearer ${"idToken"}`;
return config;
} catch (err) {}
return config;
},
(error: AxiosError) => {
return Promise.reject(error);
}
);
This axios interceptor runs whenever an api call is made whether it is invoked on server for normal data fetches or on client when an api call is made on some user interaction like onClick. Since this function runs on both client and server therefore I cannot use cookies() to fetch the cookies. Any help will be appreciated.