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

adityar15's avatar

Laravel Auth showing wrong user

I am trying to log in to the user using API. The API request is over curl as I am using Livewire.

The authentication works perfectly on a web app (the one having API code) but it does not work when called from another project. It shows the wrong user details instead of the authenticated user.

Here is the code

 $details = [
        'label'=>'Customer', 
        'email'=>$request->email, 
        'password'=>$request->password, 
        ];


        if(Auth::guard('web')->attempt($details, $request->remember_me))
        {

//do some processing
           

            return response()->json([
                'status' => 200,
                'data'   => $data
            ]);
        }


The array keys are exactly as per the database column. Could someone please help? What I am doing wrong?

0 likes
5 replies
adityar15's avatar

@hadayat That's all I could share. Actually, I have two users with the same email but different labels. And I am trying to get a second user but I am getting the first user details.

the line do some processing in the code is just fetching auth()->user()

 $details = [
        'label'=>'Customer', 
        'email'=>$request->email, 
        'password'=>$request->password, 
        ];


        if(Auth::guard('web')->attempt($details, $request->remember_me))
        {

$data = ['user'=>auth()->user()]
           

            return response()->json([
                'status' => 200,
                'data'   => $data
            ]);
        }

adityar15's avatar

So after spending hours and tons of search results I found a solution. I need to create an authentication process of my own. I replicated the logic of Laravel's authentication process of fetching the user and then matching credentials.

Please or to participate in this conversation.