错误状态401错误未经身份验证的Laravel护照

问题描述:

这是我第一次实施laravel护照

This is my first time implementing laravel passport

这是我的config/auth.php

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'passport',
        'provider' => 'users',
    ],
],

这是我的routes/api.phpauth:api

Route::group(['middleware' => ['auth:api']], function () {
    Route::resource('users','Users\AdminUsersController')->except([
    'create', 'edit'
    ]);
});

这就是我获取api的方式

and this is how I fetch the api

fetchUsers: async function(page_url){
     await axios.get('api/users')
     .then( response => {
          vm.users = response.data.data;
      })
     .catch( error => {
          console.log(error);
      });
 },

我正在获取未经身份验证的状态401错误.我怎样才能解决这个问题? TIA

Im getting status 401 error unauthenticated. How can I fix this? TIA

在您的 Kernel.php 文件和受保护的$ middlewareGroups 中,注释或删除'auth :api'在:

In your Kernel.php file and protected $middlewareGroups , comment or remove 'auth:api' in :

'api' => [
            'throttle:60,1',
            'bindings',
            //'auth:api',
        ],