Reputation: 597
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.
Upvotes: 0
Views: 1552
Reputation: 589
The Socialite user()
and your User
model are two different things.
Your User
model is related to the information stored in your database while the user
returned through socialite
is related to the information given to you by Facebook (or another provider)
You can find more information on logging a user through Sociliate Laravel 5.2 Socialite Facebook Login
Upvotes: 1