dimanche 3 juillet 2016

Laravel socialite authentication instance of Laravel\Socialite\Two\User given Error

i am tired of this error, i have set up everything perfectly.

Routes:

Route::get('facebook', ['as' => 'facebook', 'uses' => 'UserControllers\UserController@facebookLogin']);
Route::get('callback', ['as' => 'callback', 'uses' => 'UserControllers\UserController@callBack']);

Function:

public function facebookLogin()
{
    return Socialite::driver('facebook')->redirect();
}

/**
 * Obtain the user information from facebook.
 *
 * @return Response
 */
public function callBack()
{
    $user = Socialite::driver('facebook')->user();
    auth()->login($user);
    return redirect('/home');

    // $user->token;
}

$user = User::create(['name'=>$user->getName(), 'email'=>$user->getEmail()]);

When i create user in the database like this auth()->login($user); does not throw any error. but using only fb returned object it throws this error. Now this is clear i should use use Illuminate\Contracts\Auth\Authenticatable; this in my user model. so found a solution and added these lines to User Model.

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticatable as AuthenticableTrait;
class User extends Eloquent  implements Authenticatable
{
    use AuthenticableTrait;

but it still throws the same error.

enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire