Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

farshadf's avatar

get the user which is authenticated by fortify in api routes laravel

hi i have a laravel 8 application that uses fortify with custom views to login and register users . now i have some api routes that i want to get the logged in user details on them too . the problem is that i dont want to use passport and other packages to make the job hard to generate token and so on because most of the routes are on the web.php and just some routes are on api.php so what i have tried is like below :

        dd(auth()->guard('api')->user());

but it returns null and :

        dd(Auth::user());

again null . so is there any way to get the authenticated user in the api routes ?

0 likes
0 replies

Please or to participate in this conversation.