0

I'm using Socialite to log with Social networks on my platform. The data are inserted into my database but I'm not logged in...

This is my controller :

    $socialProvider = SocialProvider::where('provider_id',$socialUser->getId())->first();
$user = $socialProvider->user;
    dd($user);
    auth()->login($user);

The dd($user) give me :

User {#548 ▼
  #table: "users"
  #guarded: array:1 [▶]
  #fillable: array:24 [▶]
  #hidden: array:2 [▶]
  #dates: array:1 [▶]
  #persistableKey: "user_id"
  #persistableRelationship: "persistences"
  #loginNames: array:1 [▶]
  #connection: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:26 [▶]
  #original: array:26 [▶]
  #casts: []
  #dateFormat: null
  #appends: []
  #events: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #visible: []
  #permissionsInstance: null
  #rememberTokenName: "remember_token"
  #forceDeleting: false
}

I change the login call for : Auth::login($user, true); but still not working.

Kaherdin
  • 2,055
  • 3
  • 23
  • 34

2 Answers2

0

Call the facade Auth::login($user, true);

update: had a look at my own code where socialite is used. I had to pull the user out of the user table and not by an eloquent relationship. Not sure why that is. In my case, I save the facebook id into the user table:

$user = User::where('facebook_id', $socialProvider->id)->first();
Auth::login($user, true);
Dimitri Mostrey
  • 2,302
  • 1
  • 12
  • 11
0

You can try it with:

Auth::loginUsingId($user->id);

Have you set in your config/Auth.php the auth table right?

mrfr34k
  • 85
  • 11