I have one seperate database for saving logs
I have middleware that saves every request with response
public function handle($request, Closure $next, $logType)
{
$response = $next($request);
CreateLog::dispatch($request, $response, $logType)->onQueue(config('queue.queues.logging'));
return $response;
}
Everything related to auth progress works after every work complated. beacuse u used $response = $next($request);
'user_id' => auth()->id(),
Trying to save user_id like that. Everything is working perfect
But in prod server user_id is being null
In prod server project running using docker
2
Answers
The
user_id
is likely null in the logs on your production server because the authentication middleware is not functioning properly or the user is not authenticated. Verify the authentication configuration, check if the user is authenticated before accessingauth()->id()
, and ensure the session configuration is set up correctly in your production environment.you need to double check multiple things:
kernal.php
)based on your question and the problem is happening only on production so probably your issue is communication, your queue handler can’t access session data which is usually the case if you separate them into different modules and connections to improve performance so to achieve this you need to pass the information you need from one module to another so in your case
and in your
CreateLog
you store this userID and use it instead of depending on theauth