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

Spiral's avatar

Not getting logged In user in api controller

I want to get logged In a user in the API controller. But getting Null

I have a route in API of the controller in which i want to show

I'm not using JWT, Passport library for that Simple controllers in API and using in the Vuejs

0 likes
8 replies
tykus's avatar

What are you passing in the Request to identify the user?

1 like
Spiral's avatar

Thanks, @tykus for replying to me.

I'm using this in the API controller

use Auth;
$currentUser = Auth::user()->id;
\Log::info($currentUser ) 

but getting null value

tykus's avatar

What is in the Request to identify the User? You need a token, do you have one?

1 like
Spiral's avatar

Bro I want to logged-in user in API controller I have not token

I have put token in session when logged in the user but session value is also coming null in API controller methods

I'm not using any JSON library like JWT & passport for storing

I want loggedin user in the API route controller in web route controller coming but in API route controller not coming user

1 like
tykus's avatar

you need to either move the Route into the web routes file so that the Session is available, or make the session available to the api route groups

1 like
Spiral's avatar

Dear can you give me an example how can I make the session available to the API route groups

1 like
tykus's avatar

Take a look at the middlewares associated with the web group in the http Kernel class, and add the Session/Auth ones to the api group

Snapey's avatar

If you don't want to use passport or JWT and just send request from Vuejs from the logged in user's session, then you should move the route to web.php

API routes are STATELESS. There is no concept of an authenticated user

1 like

Please or to participate in this conversation.