How to check in a Vue component if a user is authenticated in Laravel?

前端 未结 4 1734
醉酒成梦
醉酒成梦 2021-02-04 07:49

As the title states, I\'m a little confused how I would tackle a method in my Vue Component with if/else statement based on if the user is logged in and authenticated with Larav

4条回答
  •  清歌不尽
    2021-02-04 08:33

    Use axios interceptors. You intercept the access denied http response code and then act accordingly.

    window.axios.interceptors.response.use(function (response) {
        return response;
    }, function (error) {
        if (419 === error.response.status) {
             location.reload();
        } else {
            //Something else you want to do or do nothing
        }
    });
    

提交回复
热议问题