B
B
Banyanchik2020-08-16 16:18:38
Laravel
Banyanchik, 2020-08-16 16:18:38

Laravel passport route without middleware, how to get authorized user?

I want to create an API for my application but I have a problem with the route.

I have the ability to add a link and I have a condition: if the user is authorized, the user's id is written, if not authorized, his u_id is written.

All this is sent to the same router, but here's the problem:

Route:: post('/link-store', ['as' = > 'api.link', 'uses' = > 'Api\[email protected]']);

here is my router and i send a request to it as authorized user but on
dd(\Auth()->user())
i get null If i do this:

Route::

middleware('auth:api')->group( function () { Route::post('/link-store', ['as' => 'api.link', 'uses' => 'Api\[email protected]']); });


then I can't access the route if I'm not authorized. What should I do? I used Laravel Passport.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
inFureal, 2020-08-16
@Banyanchik

Make an intermediate route.
Let users with uuid follow it, and if there is one, authorize it manually and redirect it to the desired route with the auth:api middleware

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question