Custom instance authentication not working Laravel 5.0

I am trying to authenticate a user but nothing happens in the controller

I am doing the following

$authUser = User::where('password', md5($user->salt . $request->get('password')))
                  ->where('email', $request->get('email'))
                  ->first(['login', 'email', 'firstname', 'lastname', 'zip_code','phone']);
if ($authUser) {
   Auth::login($authUser);
   return response()->json(['user' => $authUser]);
}

      

the response returns me the user, but for the next request I get an error that the user has not authenticated. Any idea?

+3


source to share


1 answer


Hi this is happening because you forgot to add the id field to the returned fields array, so try adding it like



$authUser = User::where('password', md5($user->salt . $request->get('password')))
                  ->where('email', $request->get('email'))
                  ->first(['id', 'login', 'email', 'firstname', 'lastname', 'zip_code','phone']);
if ($authUser) {
   Auth::login($authUser);
   return response()->json(['user' => $authUser]);
}

      

+3


source







All Articles