title: Using laravel 5.4 with Socialite ClientException Facebook error "This authorization code has been used"
body: <p>I'm having a very weird problem.</p>
  
  <p>I use Facebook login on my website.
  I't randomly fails and randomly works...</p>
  
  <p>Sometimes when i click login with Facebook it works and logs in/creates account. Then i logout and login again and it fails. when i then keep trying to login it will randomly login again in between errors.</p>
  
  <p>Error:</p>
  
  <pre><code>(1/1) ClientException
  Client error: `POST https://graph.facebook.com/v2.10/oauth/access_token` resulted in a `400 Bad Request` response:
  {"error":{"message":"This authorization code has been used.","type":"OAuthException","code":100,"fbtrace_id":"B1P9nm3GRb (truncated...)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/YrZUK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YrZUK.png" alt="enter image description here"></a></p>
  
  <p>I am currently on the latest version of Socialite.</p>
  
  <p>Callback function on socialcontroller:</p>
  
  <pre><code>$user = $service-&gt;createOrGetUser(Socialite::driver('facebook')-&gt;user());
  
  auth()-&gt;login($user);
  
  
  return redirect()-&gt;to('/home');
  </code></pre>
  
  <p>SocialAccountService:</p>
  
  <pre><code>public function createOrGetUser(ProviderUser $providerUser)
  {
  
      $account = SocialAccount::where('provider_user_id', $providerUser-&gt;getId())-&gt;first();
  
      if ($account) {
  
          return $account-&gt;user;
  
      } else {
  
          $user = User::where('facebook', $providerUser-&gt;getId())-&gt;first();
  
          if (!$user) {
  
              $password = Hash::make($providerUser-&gt;getId());
              $user = User::create([
                  'username' =&gt; $providerUser-&gt;getName(),
                  'email' =&gt; $providerUser-&gt;getEmail(),
                  'avatar' =&gt; $providerUser-&gt;getAvatar(),
                  'facebook' =&gt; $providerUser-&gt;getId(),
                  'password'=&gt; $password,
                  'level' =&gt; 0
              ]);
  
              $account = SocialAccount::create([
                  'user_id' =&gt; $user-&gt;id,
                  'provider_user_id' =&gt; $providerUser-&gt;getId(),
                  'provider' =&gt; 'facebook'
              ]);
  
          }
  
  
          return $user;
  
      }
  </code></pre>
  
  <p>Any help is appreciated!</p>