You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
974 B

  1. const token = localStorage.getItem("token");
  2. console.log(token);
  3. if (localStorage.getItem("token")===null) {
  4. // redirect to dashboard
  5. window.location.href = "/index.html";
  6. }
  7. function logout() {
  8. localStorage.removeItem("token");
  9. window.location.href = "/index.html";
  10. }
  11. let config = {
  12. "crossdomain": true,
  13. headers: {
  14. "Content-Type": "application/json",
  15. "Authorization": "Bearer " + token
  16. }
  17. };
  18. let user = {};
  19. // get user data
  20. axios.get(url + "/", config)
  21. .then(function (res) {
  22. console.log(res.data);
  23. user = res.data.user;
  24. console.log(user);
  25. document.getElementById("name").innerHTML = user.Name;
  26. document.getElementById("metal").innerHTML = user.Resources.Metal;
  27. document.getElementById("crystal").innerHTML = user.Resources.Crystal;
  28. document.getElementById("deuterium").innerHTML = user.Resources.Deuterium;
  29. document.getElementById("energy").innerHTML = user.Resources.Energy;
  30. })
  31. .catch(function (error) {
  32. console.log(error);
  33. });