I have implemented a custom Login component in my Vue project:
var Login = Vue.extend({
template: '#auth',
data: function () {
return {username: '',password: '',errorMessage:''};
},
methods : {
login: function (e) {
var _this = this;
$.ajax({
url: "/vue/api/login",
type: "POST",
async:false,
data:{
username:_this.username,
password: _this.password
},
success: function (data) {
// Should I store the token in a global variable??
router.push({
path: '/employeeList',
});
},
error:function (xhr, status, error) {
_this.errorMessage = xhr.responseText
}
});
}
}
});
After successful authentication, the login API returns a token string. Would it be better to store this token in a global variable or locally using localStorage? Also, is there a filter available that can help check if the user is logged in, allowing for appropriate redirection?