Friday, April 14, 2017

how to have a route for both authenticated users and non authenticated users

I have a issue with auth:api middleware! We have a request that is accessible for both authenticated users and none authenticated users when I define a route like this for none authenticated users:

Route::post('{user}/leads', 'UsersController@getContact');

It's ok everything work fine when a guest user requesting this route. is and I can access user wtith $request->user();

but if pass token with bearer header and get the user with $request->user() ofcource it doesn't work! because we didn't use auth:api on this route, and if we do we cant access this route with guest users! So I cant find a way that we define one route for both authenticated users that if user is authenticated we get $request->user() and none authenticated users can access that route too!

Thanks in advance.



via Hassan Shojaei

Advertisement