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

murilo's avatar
Level 10

JWT AUTH , how can I recuparate the user detales in the controller

Hello , I am trying to work with VUE Spa Applications + Laravel .

I am trying to recuparate the user detalhes that is Logged In , in the Controller becose when I have to add a POST , I need the ID of the USER that is creating this POST .

I am making the Auth with JWT class , like this example -

https://www.youtube.com/watch?v=Jd1RW-0lQOs&list=PLJpBh2VJhy5wPhAmjDB42pkHUnqolqxxq

it is working , it makes the authenticaton , and return the user detale ,to front ( VUE ). I have those credentias in the VUE , but I dont want to pass those informations by Javascript to the BACK .

this is my authentication -

use Auth;

if(auth()->guard('api')->attempt($credentials)){
    // SUCCESSS
}

I am tryng to recuparete the user like this -

     $user = Auth::guard('api')->user();
     dd($user) ; // null
    

or

 $user = Auth::guard('api');
 dd($user) ;

// result ->
JWTGuard {#280 ▼
  #lastAttempted: null
  #jwt: JWT {#286 ▶}
  #request: Request {#43 ▶}
  #user: null
  #provider: EloquentUserProvider {#317 ▶}
}


How could I recuparate the user ID in my controller ? is that a correct approutch ?

0 likes
5 replies
murilo's avatar
Level 10

Hello @Sti3bas , thanks so mutch for answer . do I have to send aways the token ?

It has this function , in this class -

    public function me()
    {
        return response()->json(auth('api')->user());
    }

I thought this could bring me back the USER , but it brings me NULL .

walidabou's avatar

You should always send the token with every request. otherways laravel won't know who is making the request.

Please or to participate in this conversation.