implementing-a-simple-middleware-with-vue-router
implementing-a-simple-middleware-with-vue-router copied to clipboard
middleware with server call is not blocker
Hi, I don't know if I am wrong something or there is a bug in the code but if a middleware has a call inside it that decides whether the request of the component passes or not, the middleware does not wait for the response of the call, it temporarily displays the component up a that the call was not answered and then blocks the component and redirects to the page specified in the middleware
DataService.setAuthentication();
DataService.get(config_app.base_url+'user_verified')
.then(response => {
if(response.data.results == true){
return next();
}
}).catch((error) => {
if(error.response.status == 403){
return router.push({name: 'must-be-verified'});
}
}).finally(() => {
return router.push({name: 'home'});
})
With this function I check if a user has verified his mail, before the function goes into the catch, however, it sends me inside my management system, when the answer arrives and it triggers catch, he will go to return router.push ({name: 'must-be-verified'}); and will update the page with this new route