Hi,
It's probably somewhere in issues but I can't find it... it's a shame that it's not in Docs. (to be honest it's great package but Documentation... )
All my API methods are under jwt.auth.
How can I access user who makes current request inside controller method ?
If you're using 0.5.9 look at JWTAuth class for a method that identifies a user through the subject claim, if you're using the develop branch JWTAuth class has the same method, and if you're using develop branch and guards for Laravel 5.2 then JWTGuard class has a method to get the user from the token.
To be more precise, with 0.5.9 just call:
$user = JWTAuth::parseToken()->authenticate();
Be sure to send a ?token=yourToken with the request
I am sending token with headers as it's more elegant way.
2016-08-12 10:32 GMT+01:00 Johannes Schobel [email protected]:
To be more precise, with 0.5.9 just call:
$user = JWTAuth::parseToken()->authenticate();
Be sure to send a ?token=yourToken with the request
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/tymondesigns/jwt-auth/issues/822#issuecomment-239402935,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AI80kpq1YrvlK5hOoxK0mYaFojMqPLOhks5qfD3AgaJpZM4JigWp
.
Is there any way to improve middleware JWTAuth to make $user available from controller without calling this method every time ?
You can write your own AuthenticatedController and let all other controllers extend from this one. Inside the __construct() method of the AuthenticatedController you can set the protected $user variable!
I would not recommend adding logic to the middleware. The middleware should - at least in my opinion - just check the requests!
I used
Config::set('auth.model', App\Customer::class)
To authenticate from the customers table and I'm getting my token but I can't use my token to get my customers details from customers table even though I used JWTAuth::parseToken()->authenticate()
Please help.
The user is also available via Auth as:
$user = Auth::user();
I use $user = JWTAuth::parseToken()->toUser(); in my controller method to fetch the current user and it is working fine, while the route to this method is protected by jwt middleware.
Most helpful comment
Is there any way to improve middleware JWTAuth to make $user available from controller without calling this method every time ?