I want to save the token in the cookie and run the navigation ("/"). In "/", it is implemented so that the token value is implemented. Therefore, I want to use setCookie to run navigate after the token value comes in. I think we should use async await, so we tried a lot, but we failed.(I'm using the react-cookie library.)
const [cookies, setCookie, removeCookie] = useCookies("token");
axios
.post(`${process.env.REACT_APP_API}/normal_login/`, formData)
.then((response) => {
if (response.data) {
console.log(response.data.account_token);
setCookie("token", response.data.account_token, {
path: "/",
});
console.log("cookies", cookies);
// navigate("/");
}
})
.catch((err) => {
console.log("==>", err);
});
Error: Request failed with status code 401
at createError (createError.js:16:1)
at settle (settle.js:17:1)
at XMLHttpRequest.onloadend (xhr.js:66:1)