How to Auth::check() user on Laravel with API calls

前端 未结 4 801
[愿得一人]
[愿得一人] 2021-01-21 07:54

I\'m using VueJS in my front-end, so I have this API call somewhere in the front-end code:

let products = axios.get(\'api/products\');


4条回答
  •  不要未来只要你来
    2021-01-21 08:17

    You can check user Auth of API calls by this:

    At first add this use code in your Class:

    use Auth;
    

    Then add this code in your function:

        if (Auth::guard('api')->check())
        {
            logger(Auth::guard('api')->user()); // to get user
    
        }else{
            logger("User not authorized");
        }
    

提交回复
热议问题