0

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:

enter image description here

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);
  }
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Shaan
  • 475
  • 3
  • 20
  • Did you tried: `$user = $service->createOrGetUser(Socialite::driver('facebook')->stateless()->user());` ? – mare96 Apr 18 '20 at 14:37
  • @mare96 I just injected your code and there is a new error. Class App\SocialFacebookAccount contains 6 abstract methods and must therefore be declared abstract or implement the remaining methods (Illuminate\Contracts\Auth\Authenticatable::getAuthIdentifierName, Illuminate\Contracts\Auth\Authenticatable::getAuthIdentifier, Illuminate\Contracts\Auth\Authenticatable::getAuthPassword, ...) – Shaan Apr 18 '20 at 14:42

0 Answers0