Laravel中间件正在从子目录返回未经验证的生产服务器



我正在发送一个API请求,以在登录后获取用户详细信息我有一个项目,我只在其中运行api,我把这个项目放在名为api的子目录中。所以前端运行在react JS中内置的根上。

另外,我已经从RouteServiceProvider中删除了API前缀,因为我不想调用domain.com/api/api

路线:

Route::group(['namespace' => 'Auth'], function(){
...
Route::post('login','LoginController@login'); // Running successfully
Route::middleware('auth:api')->get('/user', 'LoginController@user'); // Returning 401 unauthenticated
});

路由服务提供商

protected function mapApiRoutes()
{
Route::middleware('api')
->as('api.')
->namespace($this->namespace."\API")
->group(base_path('routes/api.php'));
}

尝试过的解决方案

1( 我已经在AppServiceProvider中的boot方法中放置了Passport::withoutCookieSerialization();

2( 我已经在AuthServiceProviderboot方法中放置了Passport::$ignoreCsrfToken = true;

提前感谢

我自己找到了解决方案。

我已经将这些行添加到放在Laravel项目根目录中的.htaccess文件中(不是公共的(。

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

相关内容

最新更新