api-guard icon indicating copy to clipboard operation
api-guard copied to clipboard

$this->user Null

Open morganzysman opened this issue 8 years ago • 4 comments

Hello guys,

I use to be working with the version 2.

I'm now starting a new project with 3.1.1. My controllers extend ApiController and ApiController itself extends ApiGuardController.

The key validation is working just fine, what I can't seem to get working is the $this->user. it seems to always be null.

Regards,

Morgan

morganzysman avatar May 05 '16 00:05 morganzysman

Hi @morganzysman is the api_key associated with a user_id? What auth library are you using?

chrisbjr avatar May 05 '16 00:05 chrisbjr

Hello, yes it is associated with a user_id.

I'm not using any auth library

Regards

morganzysman avatar May 05 '16 00:05 morganzysman

I'm having the same problem, keeps coming up with null. It appears that it's authorising the user once $this->auth->onceUsingId($id) but actually you're trying to retrieve the user from the $auth object a second time when you try and access it from the controller. @chrisbjr I could be wrong but I'm guessing a fix would be to save the user as a property in the singleton ApiGuardAuth class, instead of accessing it numerous times from the $auth object. Otherwise @morganzysman without modifying the library, you can access the user from the Illuminate\Http\Request instance

wasimkham avatar Jun 03 '16 13:06 wasimkham

I created a pull request for this issue: #143

osugregor avatar Jan 06 '17 19:01 osugregor