api接口401问题

用的jwt。
auth.php

'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

    /*
    |--------------------------------------------------------------------------
    | Authentication Guards
    |--------------------------------------------------------------------------
    |
    | Next, you may define every authentication guard for your application.
    | Of course, a great default configuration has been defined for you
    | here which uses session storage and the Eloquent user provider.
    |
    | All authentication drivers have a user provider. This defines how the
    | users are actually retrieved out of your database or other storage
    | mechanisms used by this application to persist your user's data.
    |
    | Supported: "session"
    |
    */

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

    /*
    |--------------------------------------------------------------------------
    | User Providers
    |--------------------------------------------------------------------------
    |
    | All authentication drivers have a user provider. This defines how the
    | users are actually retrieved out of your database or other storage
    | mechanisms used by this application to persist your user's data.
    |
    | If you have multiple user tables or models you may configure multiple
    | sources which represent each model / table. These sources may then
    | be assigned to any extra authentication guards you have defined.
    |
    | Supported: "database", "eloquent"
    |
    */

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],
        'accounts' => [
            'driver' => 'eloquent',
            'model' => App\Models\Admin\Account::class,
        ],
        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

api.php路由文件

Route::group(['middleware' => ['auth:api', 'checkAuth']], function () {
        // 用户管理
        Route::resource('account', 'AccountController')->except(['create', 'edit']);
        // 状态
        Route::patch('account/{account}/status', 'AccountController@changeStatus')->name('account.status');
        // 角色管理
        Route::resource('role', 'RoleController')->except(['create', 'edit']);
        // 权限管理
        Route::resource('permission', 'PermissionController')->except(['create', 'edit']);
    });

登录后总是出现如下是什么原因,刷新下就可以正常访问

![api登录问题]
api接口401问题

api接口401问题

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 3

检查一下第一次请求的时候有没有带token

2年前 评论
laravel_peng
  1. 根据图上请求看,checkNewMessage 接口鉴权失败了。

    file

  2. 查看这个请求是在那个业务流程中发出的,然后再看 checkNewMessage 接口里面的逻辑,是缺少什么参数会导致鉴权失败。

2年前 评论

把headers的图一并截取了才行啊!

2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!