How to handle login JWT token in Vue JS?
P粉587780103
P粉587780103 2024-03-30 16:39:37
0
1
431

There is a token in my localstorage. If I delete the token in localstorage then I don't log out. Can you give me an example of how to do this?

created() {
  if (this.vueToken) {
  let headers = {
    Authorization: "Bearer " + localStorage.getItem("vueToken"),
  };

  axios
    .get("checkLogin", {
      headers: headers,
    })
    .then((response) => response);
}else{
    this.$router.push('/login')
}
  },

P粉587780103
P粉587780103

reply all(1)
P粉511896716

You must set a condition in the security route, for example, if the token in local storage is empty, push it to local storage. Here is sample code.

mounted() {
this.token = localStorage.getItem("ivToken");    
if(this.token===null){     
  this.$router.push("/signin")
}

},`

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template