diff --git a/src/LaravelAuthQueueServiceProvider.php b/src/LaravelAuthQueueServiceProvider.php index 053ecf1..adb7406 100644 --- a/src/LaravelAuthQueueServiceProvider.php +++ b/src/LaravelAuthQueueServiceProvider.php @@ -3,17 +3,24 @@ namespace DatPM\LaravelAuthQueue; use Illuminate\Queue\Queue; +use Illuminate\Queue\SyncQueue; use Illuminate\Support\Facades\Auth; use Illuminate\Support\ServiceProvider; use DatPM\LaravelAuthQueue\Guards\KernelGuard; use Illuminate\Contracts\Database\ModelIdentifier; use DatPM\LaravelAuthQueue\Traits\WasAuthenticated; +use Illuminate\Support\Facades\Queue as QueueManager; class LaravelAuthQueueServiceProvider extends ServiceProvider { public function boot() { Queue::createPayloadUsing(function ($connectionName, $queue, $payload) { + // Ignore adding extra payload for Sync Queue + if (QueueManager::connection($connectionName) instanceof SyncQueue) { + return []; + } + // Skip attaching authUser when the job does not use WasAuthenticated Trait if (! in_array(WasAuthenticated::class, class_uses_recursive($payload['displayName']))) { return []; diff --git a/src/Middlewares/RestoreAuthenticatedContextMiddleware.php b/src/Middlewares/RestoreAuthenticatedContextMiddleware.php index adddc9c..a2cec7c 100644 --- a/src/Middlewares/RestoreAuthenticatedContextMiddleware.php +++ b/src/Middlewares/RestoreAuthenticatedContextMiddleware.php @@ -2,6 +2,7 @@ namespace DatPM\LaravelAuthQueue\Middlewares; +use Illuminate\Queue\Jobs\SyncJob; use Illuminate\Support\Facades\Auth; use Illuminate\Queue\SerializesModels; use Illuminate\Contracts\Auth\Authenticatable; @@ -12,6 +13,11 @@ class RestoreAuthenticatedContextMiddleware public function handle($command, callable $next) { + // If the job is being handled in sync, skip restore logic + if ($command->job instanceof SyncJob) { + return $next($command); + } + Auth::shouldUse('kernel'); $guard = auth();