I basically have a Nav component with Link to a add_repo page. Now in my home page I set Context data to have an access token.
const response = await fetch("api/get-access-token", {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(reqBody),
});
const resData = await response.json();
console.log(resData);
setToken(resData.access_token);
authCtx.tokenHandler(resData.access_token);
Now on routing to my add_repo page I'm sending a request to api route to make a new repository on github.
where I use the previously stored token.
const [token] = useState(authCtx.token);
I need to pass updated token value from the context but there the context is the initial state context(null).
console.log(authctx.token) #null
also the request fails as the token passed is null
I tried to send request to github with the data entered on add_repo page. but github returns with a "authentication required" message. as the token is null in the context