laravel-shopify
laravel-shopify copied to clipboard
Unable to get Auth::user() in AfterAuthenticateJob
I tried registering after authenticate job just like we do it versions before 17, and then i tried to get Auth::user(), but it returns null
here is my job registration
'after_authenticate_job' => [ [ 'job' => \App\Jobs\AfterAuthenticateJob::class, 'inline' => env('AFTER_AUTHENTICATE_JOB_INLINE', true) ], ],
And i my job code is public function handle() { $user = Auth::user(); dd($user); // returns null
}
Hmm, we may need to mod this to directly input the user into the job.
Sorry brain fart... @yasir-naseer-tetralogicx The shopdomain should be in the constructor already, you need to look the shop up based on this.
@yasir-naseer-tetralogicx
Something like this:
public function __construct($shopDomain, $data)
{
$this->shopDomain = $shopDomain;
$this->data = $data;
}
public function handle()
{
$user = User::where('name', $this->shopDomain)->firstOrFail();
// do stuff here
}
For me only 1 variable in constructor works
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Helper;
class AfterAuthenticateJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $shopDomain;
protected $data;
protected $shop;
// public function __construct($shopDomain, $data)
// {
// Log::info("Constructor - start- shopDomain".$shopDomain);
// Log::info($data);
// Log::info("Constructor - end");
// $this->shopDomain = $shopDomain;
// $this->data = $data;
// }
public function __construct($shop)
{
Log::info("Constructor2 - start");
Log::info($shop);
Log::info("Constructor2 - end");
$this->shop = $shop;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Log::info("AfterAuthenticateJob-=call=start-".Date('Y-m-d h:i:s'));
// Log::info("shopDomain".$this->shopDomain);
// $this->shop = User::where('name', $this->shopDomain)->firstOrFail();
Helper::createSearchPage($this->shop);
Log::info("AfterAuthenticateJob-=call=end-".Date('Y-m-d h:i:s'));
}
}
Closing as a stale issue, $shopDomain is in the constructor for the later versions and this looks like it could be an older version of the package.