redxzeta / Awesome-Adoption

pet adoption near your area
https://pawternityhub.netlify.app/
MIT License
59 stars 132 forks source link

Storing the api key #30

Closed redxzeta closed 3 years ago

redxzeta commented 3 years ago

Maybe store it in localstorage or something so there won't be in constant requests in App.js?

Unless someone has a better solution

 const [token, setToken] = useState("");
  useEffect(() => {
    axios
      .post(
        "https://api.petfinder.com/v2/oauth2/token",
        `grant_type=client_credentials&client_id=${process.env.REACT_APP_PETFINDER_KEY}`
      )
      .then((response) => {
        setToken(response.data.access_token);
      })
      .catch((error) => {
        console.log(error);
      });
  }, []);
klee214 commented 3 years ago

Although redux + local storage would be the best solution, storing the token into the local storage will absolutely work in this case.