I'm developing a project on Laravel 6. Just implemented the Facebook Login Method and it stopped to work when called callback method in URL. Here is the error:
Although it seems to a common problem and have been tackled before but I think the solution proposed in below link was for Laravel 5 not for Laravel 6. This is the link:
Laravel Socialite: InvalidStateException
When I search the web about it, I found the fact there are many programmers stuck on the same issue with Laravel 6 but no any solution was provided regarding this.
services.php
'facebook' => [
'client_id' => env('FACEBOOK_APP_ID'),
'client_secret' => env('FACEBOOK_APP_SECRET'),
'redirect' => 'http://localhost:8000/facebook/callback',
],
.env
FACEBOOK_APP_ID=**********
FACEBOOK_APP_SECRET=************
SocialAuthFacebookController.php
class SocialAuthFacebookController extends Controller
{
public function redirect()
{
//return Socialite::driver('facebook')->redirect();
return Socialite::driver('facebook')->stateless()->redirect();
}
public function callback(SocialFacebookAccountService $service)
{
$user = $service->createOrGetUser(Socialite::driver('facebook')->user());
auth()->login($user);
return redirect()->to('/home');
}
}
}
SocialFacebookAccount.php
class SocialFacebookAccount implements Authenticatable
{
protected $fillable = ['user_id', 'provider_user_id', 'provider'];
public function user()
{
return $this->belongsTo(User::class);
}
}
