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.

44 lines
1.2 KiB

  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. function getUser() {
  21. axios.get(url + "/", config).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. // if (localStorage.getItem("mainplanet") === null) {
  31. localStorage.setItem("mainplanet", res.data.user.Planets[0]);
  32. // }
  33. }).catch(function(error) {
  34. console.log(error);
  35. });
  36. }
  37. getUser();
  38. setInterval(getUser, 5000);