are you logging the user into your Laravel application once you get the code? I ask because this will reinitialise the session.
Session values getting nulled
Hey guys, I have a problem with session variables getting nulled on certain curcumstances. If a user logs into the clients single sign on solution he gets redirected to the Laravel application. With this initial request a special header will be sent. I need to retrieve the value from the header to be able to get user details from the database. I planned to retrieve the header in a Middleware (added to the web middleware group), get the details from the database and write the details into a session variable.
This approach works for the initial request, but after that, all requests will result in nulled session values.
<?php
namespace App\Http\Middleware;
use Closure;
use App\Models\UserDetail;
class CheckHeaders
{
public function handle($request, Closure $next)
{
if ($request->headers->has('useridentifier')) {
$userident = $request->header('useridentifier');
$user = UserDetail::where('useridentifier', $userident)->first();
session([
'user' => [
'fn' => $user->firstname,
'ln' => $user->lastname,
'org' => $user->organisation,
]
]);
return $next($request);
}
return abort(410);
}
}
The result of the first request is:
'user' => [
'fn' => 'jane',
'ln' => 'doe',
'org' => 'abc'
]
The result of every following request is always:
'user' => [
'fn' => null,
'ln' => null,
'org' => null
]
What am I missing?
Please or to participate in this conversation.