{"size": 1136, "ext": "js", "max_stars_repo_path": "packages/koa-jwt/brower/index.js", "max_stars_repo_name": "huomarvin/easy-to-understand", "max_stars_repo_stars_event_min_datetime": "2021-09-13T15:02:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-23T03:00:59.000Z", "max_issues_repo_path": "packages/koa-jwt/brower/index.js", "max_issues_repo_name": "huomarvin/easy-to-understand", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/koa-jwt/brower/index.js", "max_forks_repo_name": "huomarvin/easy-to-understand", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 4, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.7027027027, "max_line_length": 73, "alphanum_fraction": 0.5642605634}
const name = document.getElementById("name");
const password = document.getElementById("password");

document.getElementById("form").addEventListener("submit", (e) => {
  e.preventDefault();
  fetch("/login", {
    method: "POST",
    body: JSON.stringify({ name: name.value, password: password.value }),
    headers: {
      "content-type": "application/json",
    },
  })
    .then((res) => res.json())
    .then((json) => {
      console.log(json);
      localStorage.setItem("token", json.token);

      let getUserBtn = document.getElementById("button");
      if (!getUserBtn) {
        getUserBtn = document.createElement("button");
        getUserBtn.id = "button";
        getUserBtn.innerHTML = "获取用户信息";
        getUserBtn.onclick = () => {
          console.log(localStorage.getItem("token"));
          fetch("/getLoginInfo", {
            headers: {
              Authorization: "Bearer " + localStorage.getItem("token"),
            },
          })
            .then((res) => res.json())
            .then((res) => alert(res.tokenData.name));
        };
        document.body.appendChild(getUserBtn);
      }
    });
});
