I\'m using Laravel Socialite to add a Facebook connect button on a website. Sometimes, I\'ve got this error on callback:
exception \'Laravel\\Socialite\\Two\
I had the same problem and I just cleared the cache to solve this problem. I just ran this command and started the process again.
php artisan cache:clear
I hope this answer may help someone.
If you still need help you can use my code, it works for me. You just need to create two routes and update the users table. Don't forget to make password nullable, since you won't get one from the facebook users The code in my controller:
public function redirectToProvider()
{
return Socialize::with('facebook')->redirect();
}
public function handleProviderCallback(User $user)
{
$money = Socialize::with('facebook')->user();
if(User::where('email', '=', $money->email)->first()){
$checkUser = User::where('email', '=', $money->email)->first();
Auth::login($checkUser);
return redirect('home');
}
$user->facebook_id = $money->getId();
$user->name = $money->getName();
$user->email = $money->getEmail();
$user->avatar = $money->getAvatar();
$user->save();
Auth::login($user);
return redirect('home');
}
Finally i solved by :
Redirect URL in .env
file should be the same URL in google developer account
double check on your redirects urls .
I stacked on this two day and changing 'driver' => env('SESSION_DRIVER', 'file')
to 'driver' => env('SESSION_DRIVER', 'cookie')
worked for me
I want to share you my solution . I go to my AbstractProvider.php
file and in the line of problem
public function user()
{
if ($this->hasInvalidState()) {
throw new InvalidStateException;
}
// ...
}
I stop the throw new InvalidStateException
and call the redirect function like that:
public function user()
{
if ($this->hasInvalidState()) {
$this->redirect();
// throw new InvalidStateException;
}
// ...
}
InvalidStateException
is a red herring and the true root cause is some other bug. It took me ~12 hours one time to realize that I hadn't added a new field to the $fillable
array in the model.$provider->user()
can only be called once per request because the inside of that function calls hasInvalidState()
, which then removes the 'state' entry from the session. It took me hours to realize that I happened to be calling $provider->user()
multiple times, when I should have called it just once and saved the result to a variable.