I'm coding an POS-system in laravel and vuejs. To login I'm using JWT-auth. Now if there is a already a "cash session" the system needs to redirect to a vue-route /Dashboard
, if not you need to redirect to /Cash
. Now I've tried various things but nothing works. It always redirect to /Cash
.
Does anyone have a solution?
methods: {
login() {
let app = this;
this.$auth.login({
params: {
username: app.username,
password: app.password
},
success: function () {
},
error: function (resp) {
alert('Error: ' + resp.response.data.msg)
},
redirect: app.redirectURL(),
fetchUser: true
});
},
setText(gebruiker) {
this.buttonText = gebruiker;
this.username = gebruiker;
},
redirectURL () {
let cashActive = false;
axios.get('cash/active').then(response => {
console.log(response.data.active);
cashActive = response.data.active;
});
console.log("Cash Active: " + cashActive);
if (!cashActive) {
console.log("Return /Cash");
return "Cash";
} else {
console.log("Return /dashboard");
return "/Dashboard";
}
}
}
EDIT: I've tried asynchronous function, but redirect still doesn't work. My page doesn't redirect. There must be an issue with what I return in the function redirectURL. Can anyone help?
methods: {
login() {
let app = this;
this.$auth.login({
params: {
username: app.username,
password: app.password
},
success: function () {
},
error: function (resp) {
alert('Error: ' + resp.response.data.msg)
},
redirect: app.redirectURL(),
fetchUser: true
});
},
setText(gebruiker) {
this.buttonText = gebruiker;
this.username = gebruiker;
},
async redirectURL () {
let cashActive = await axios.get('cash/active').then(response => {
//console.log(response.data.active);
return response.data.active;
});
console.log("Cash Active: " + cashActive);
if (!cashActive) {
console.log("Return /cash");
return "/cash";
} else {
console.log("Return /dashboard");
return "/dashboard";
}
}
},
}