headers() function don't work
Unanswered
Flemish Giant posted this in #help-forum
Flemish GiantOP
Hi everyone, Im new to the nextjs framework so please bear with me, Im trying to check if the "X-XSRF-TOKEN" header exists using the headers() functions by following the steps in the nextjs docs : https://nextjs.org/docs/app/api-reference/functions/headers, but it shows me this error in the console : Error: Invariant: Method expects to have requestAsyncStorage, none available.
Im using the function in my axios file precisely in the request interceptor where Im verifying the existence of the "X-XSRF-TOKEN" header, here's the code im working with:
Im using the function in my axios file precisely in the request interceptor where Im verifying the existence of the "X-XSRF-TOKEN" header, here's the code im working with:
axiosClient.interceptors.request.use(if you please have any suggestions or advices feel free to express yourselves ðŸ™
(config: InternalAxiosRequestConfig) => {
if (window.location.pathname !== "/login") {
if (headers().has("X-XSRF-TOKEN")) {
console.error("header exists");
} else {
console.error("no header");
}
}
return config;
},
(error: AxiosError) => {
return Promise.reject(error);
}
);