Closed shinnlu closed 1 month ago
Hi The issue is not not connected to this repo, rather than it is a issue with the laravel itself.
Laravel processes the jobs in another process rather than whether the server is running. So it is not possible to get authenticated user inside a job. If you need to access the authenticated user inside a job, you need to pass it to the constructor of the job class.
For the csrf token issue, it meant to protect your browser session. It won't protect sessions of the other browser. I think, the issue has nothing to do with this repo.
Hope this clarify the issues. Thanks
Thanks for the reply, i didn't mean to access authenticated user in job. when I dispatch a long run job to background (with QUEUE_CONNECTION=database), the frontend gets Unauthenticated frequently.
Thanks for the added info. Are you locking the users table while processing on the background? Because on the frontend when route changes, it sends a http request to sync auth user using AuthController@verify method. As it is returning null, Please have a look on the background process logic and make sure that user table is not locked and laravel authentication logic works as expected during the job processing.
In general, using database queue_connection for job processing is not a good idea because of the database transactions and dead locks. Firstly you can try with after_commit: true on the database queue config. If not solved, you should test with using something like redis. you may look into the following: https://laravel.com/docs/11.x/queues#jobs-and-database-transactions https://github.com/laravel/framework/issues/31660
I am pretty sure, this problem is not related to this repo.
The dispatched job was not related with users table, it's fetch data from Api and write to database with no transaction. and the route didn't change, the error occurs while i load next page from pagination. I have changed queue_connection to redis and with after_commit: true, still same issue. I have checked the request header from chrome inspect, there are the same with success and failed request, error occurs randomly.
Hi Please reproduce and share the usecase if possible. Without the exact usecase, I am not able to resolve the issue.
As no activities on this issue. Closing this.
Hi, The error occurred when i was running jobs for a long time, Unauthenticated usually happened. the problem was in AuthController->verify() function, Auth::id() returns empty when job running.
I open another browser when the job is running, CSRF token mismatch happened randomly.