设置数据后为空会话

时间:2019-07-14 18:22:52

标签: php laravel session

我正在使用Laravel做一个简单的API,并且在尝试将数据保存到会话变量中时遇到问题。

当用户尝试登录该应用程序时,我的LoginController具有以下功能:

public function postAction (Request $request) {
    ...
    $request->session()->put('user', 'helloooooo');
    ...
}

此后,当该用户尝试获取有关其个人资料的某些信息时,我有一个名为middleware的{​​{1}}来检查是否设置了他的会话:

VerifyUser

我将public function handle(Request $request, Closure $next) { if (session('user') != null) { return $next($request); } $response = array(); $response['status'] = 'KO'; $response['code'] = 401; $response['user'] = $request->session()->all(); return response()->json($response, 401); } 字段设置为user,以查看会话中的内容。

但是我的前端始终收到401响应,并且会话始终具有以下值:

  

代码:401状态:“ KO”用户:{…}   _token:“ 9tesUdneGlK1w9685jhaWYatEKSpcFJkKyJQNnjQ”

这是我的$request->session()->all();

middlewares

这是我的protected $middleware = [ CheckForMaintenanceMode::class, ValidatePostSize::class, TrimStrings::class, ConvertEmptyStringsToNull::class, TrustProxies::class, StartSession::class, QueryExceptionHandler::class, ]; /** * The application's route middleware groups. * * @var array */ protected $middlewareGroups = [ 'web' => [ EncryptCookies::class, AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, AuthenticateSession::class, ShareErrorsFromSession::class, SubstituteBindings::class, ], 'api' => [ 'throttle:60,1', 'bindings', ], 'web-out' => [ Authorization::class, ], 'web-in' => [ VerifyUser::class, ], ]; 文件:

web.php

我在做什么错了?

谢谢!

0 个答案:

没有答案