I'm a selftaught (web) developer. On sunny days, you can find me hiking through the Teutoburg Forest, on rainy days coding or with a good fiction novel in hand.
In your fetch request in useFetch, you are directly assigning headers as a second function parameter to the fetch method.
Try and rewrite your useFetch - function to assign the headers to the options object and pass this into the fetch() - function.
If that won't work, please state what backend you're using. For reference, you can also check MDN
constuseFetch=(url,headers)=>{const[data,setData]=useState([]);const[loading,setLoading]=useState(true);// Assign headers to options objectconstoptions={headers:headers}useEffect(async()=>{// Pass options as second argument instead of headersconstresponse=awaitfetch(url,options)constdata=awaitresponse.json()// console.log(data)setData(data)setLoading(false)},[]);return{data,loading};}
Hey. I am not directly assigning headers as second param in useFetch. If you observe api_headers it contains headers, method, etc.... have you misunderstood this? My bad, I shouldn't have named the second param as headers
Below is api_headers which I am passing which again consists of headers, method etc...
I'm a selftaught (web) developer. On sunny days, you can find me hiking through the Teutoburg Forest, on rainy days coding or with a good fiction novel in hand.
Ye, that slipped my attention, my apologies.
The rest of your code doesn't look suspicious. Since you're storing the token in your state, you could try and instead save it as a clientside cookie, explicitly sending it to your backend. Else, I'd see for the backend documentation or verify error logs, if available.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In your fetch request in useFetch, you are directly assigning headers as a second function parameter to the fetch method.
Try and rewrite your useFetch - function to assign the headers to the options object and pass this into the fetch() - function.
If that won't work, please state what backend you're using. For reference, you can also check MDN
Tried it. Facing the same issue again. Please refer below screenshot
i.imgur.com/07swAGc.png
Also, I do not have control over the backend API's
Hey. I am not directly assigning headers as second param in useFetch. If you observe
api_headers
it contains headers, method, etc.... have you misunderstood this? My bad, I shouldn't have named the second param as headersBelow is api_headers which I am passing which again consists of headers, method etc...
Ye, that slipped my attention, my apologies.
The rest of your code doesn't look suspicious. Since you're storing the token in your state, you could try and instead save it as a clientside cookie, explicitly sending it to your backend. Else, I'd see for the backend documentation or verify error logs, if available.