0
votes

Laravel JWTAuth::encode , JWTAuth::attemp , JWTAuth::fromUser, unable to create a token, and throwing error

Thats the whole response I am getting,

Error Response Image a

Error Response Image b

the login route in routes.php is like this:

Route::post('auth/login','authController@login');

and the login function in authController.php is like this:

    function login(Request $request){

    $user = User::where('email', '=',$request['email'])
        ->first(['first_name', 'last_name', 'email', 'id', 'hashed_password']);
    // if email and password is wrong
    if(count($user) <= 0 )
            return response(["success"=>false,"message"=>"Authentication failed, wrong credentials"],401);
        //sendResponse(false, "Authentication failed, wrong credentials", null, 401);
    if (!Hash::check($request['password'], $user['hashed_password']))
    {
        return response(["success"=>false,"message"=>"Authentication failed, wrong credentials"],401);
    }
    try{
        // attemp to verify the credentials and create a token for the user
        $payload = JWTFactory::make($user['original']);
        $token = JWTAuth::encode($payload);
        $user['jwt'] = $token;
        $user->save();
    }
    catch(Exception $e){
        // something went wrong while creating token or updating user
        return response(["success"=>false,"message"=>"There's something wrong, we will get back to you soon."],400);
    }

    $content['message'] = "Successfully Login";
    $content['success'] = true;
    $content['token'] =  $user['jwt'];
    $content['data']['first_name'] = $user['first_name'];
    $content['data']['last_name'] = $user['last_name'];
    $content['data']['email'] = $user['email'];
    return response($content,200)
        ->header('Content-Type', "application/json");

}

I am stuck on this error for two days, and still unable to find a solution. Tried to maximize the nesting level by adding the following line in my php.ini

;xdebug.max_nesting_level=1000

but it didn't work.

Kindly help.

1

1 Answers

0
votes

Looking at your error message, it is still acting on the default xdebug.max_nesting_level.

From what you've showed that you changed in your php.ini file - you've updated your xdebug.max_nesting_level but left it commented out so that it won't take any affect.

You need to uncomment it by removing the ; before it, so that it looks like this:

xdebug.max_nesting_level=1000

Then restart your services for it to take affect.