Mic*_*ael 6 middleware laravel
我正在用 Laravel 构建我的第一个 API,我正在使用 JWT 进行身份验证。我还不太了解守卫,但我想我设法守卫了我的 User 类。因此,当我尝试到达 UserController 中的路由时,它会受到保护,如果用户未通过身份验证,则会调用 Authenticate 中间件。问题是,当我尝试通过 Postman 使用 API 路由时,出现以下错误
ErrorException: 标头不能包含多个标头,在文件中检测到新行
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
class Authenticate extends Middleware
{
protected function redirectTo($request)
{
if (!$request->expectsJson()) {
return response()->json(['message' => 'Unauthorized'], 403);
}
}
}
Run Code Online (Sandbox Code Playgroud)
api.php
<?php
use Illuminate\Support\Facades\Route;
Route::post('register', 'AuthController@register');
Route::get('user/{id}', 'UserController@index');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1254 次 |
| 最近记录: |