简体   繁体   English

如何修复以下错误:InvalidArgumentException: Auth guard [jwt] is not defined

[英]How to fix following error: InvalidArgumentException: Auth guard [jwt] is not defined

I have followed following guide to make an Authentication Api, and an api which uses the authentication from the first one.我按照以下指南进行了身份验证 Api 和使用第一个身份验证的 api。 I have done everything exactly the same, but i still get this error:我所做的一切都完全相同,但我仍然收到此错误:

InvalidArgumentException: Auth guard [jwt] is not defined. InvalidArgumentException:未定义身份验证保护 [jwt]。 in file folder/to/project/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php on line 84在第 84 行的文件夹/to/project/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php

The guide i have followed is: https://medium.com/swlh/build-jwt-authentication-between-multiple-api-with-laravel-fbd03352aaa3我遵循的指南是: https://medium.com/swlh/build-jwt-authentication-between-multiple-api-with-laravel-fbd03352aaa3

My config/auth looks like this:我的config/auth如下所示:

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

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

    'api' => [
        'driver' => 'jwt',
        'provider' => 'users',
        // 'hash' => false,
    ],
],

Then my app/guard/JWTGuard.php looks exactly like in the guide.然后我的app/guard/JWTGuard.php看起来与指南中的完全一样。 My routes/api.php look the following:我的routes/api.php如下所示:

Route::middleware('auth:jwt')->resource('projects', ProjectController::class);

Does anybody has this issue before and know how to solve it?以前有人遇到过这个问题并且知道如何解决吗?

The problem was in routes/api.php .问题出在routes/api.php中。 The middleware shouldn't be "auth:jwt", but "auth:api".中间件不应该是“auth:jwt”,而是“auth:api”。 This did the trick for me.这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM