0

I have the following route in my routes/api.php

Route::get('/games/{game}', 'GamesController@show')->name('api.games.show');

On client side, I already included Authorization bearer token header in every AJAX request.

How can I retrieve the value of the user associated with the token throught $request->user() without having to require authentication (without having to use ->middleware('auth:api'))

Basically what I want is to have one route that serves for both authenticated (with token) and non authenticated (without token) requests.

xar
  • 1,429
  • 2
  • 17
  • 29
  • You would have to create your own middleware to essentially do exactly what `auth:api` already does, which is pseudo-JWT authentication (I believe it actually also uses sessions) – Derek Pollard Jun 05 '18 at 15:38
  • @Derek that's what I had in mind too but I haven't had the time to dig deeper. I'm hoping someone already solve this issue could give me some snippet. – xar Jun 05 '18 at 15:40
  • Why not just use the pre-built `auth:api` ? – Derek Pollard Jun 05 '18 at 15:42
  • Facing same issue/ hurdle... did you find a solution? – Edwin Krause Sep 30 '18 at 13:28
  • In case, if someone will find this question first, here is the answer: https://stackoverflow.com/questions/50709659/laravel-5-6-how-to-get-auth-user-or-response-user-in-api-controller Idk, why this is have higher priority in google – GONG Mar 28 '19 at 20:20

0 Answers0