title: socialite Google Login shows "The page isn’t redirecting properly"
body: <p>I am trying to setup Google Login using socialite in Laravel. But when I enter the Google credentials, it shows:</p>
  
  <blockquote>
    <p>The page isn’t redirecting properly</p>
  </blockquote>
  
  <p>for  the url <code>http://127.0.0.1:8000/redirect/google</code>.</p>
  
  <p><strong>My web.php is:</strong></p>
  
  <pre><code>Route::get('/redirect/google', 'SocialAuthController@redirect');
  Route::get('/callback/google', 'SocialAuthController@callback');
  </code></pre>
  
  <p><strong>services.php:</strong></p>
  
  <pre><code>'google' =&gt; [
      'client_id' =&gt; '-----.apps.googleusercontent.com',
      'client_secret' =&gt; '---------',
      'redirect' =&gt; 'http://127.0.0.1:8000/callback/google'
  ],
  </code></pre>
  
  <p><strong>SocialAuthController.php:</strong></p>
  
  <pre><code>namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use App\SocialAccountService;
  use Socialite;
  
  class SocialAuthController extends Controller {
      //
      public function redirect(){
          return Socialite::driver('google')-&gt;redirect();
      }
  
      public function callback(SocialAccountService $service) {
          $user = $service-&gt;createOrGetUser(Socialite::driver('google')-&gt;user());
          auth()-&gt;login($user);
          return redirect()-&gt;back();
      }
  }
  </code></pre>
  
  <p><strong>SocialAccount.php :</strong></p>
  
  <pre><code>namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class SocialAccount extends Model {
      //
      protected $fillable = ['user_id', 'provider_user_id', 'provider'];
  
      public function user() {
          return $this-&gt;belongsTo(User::class);
      }
  }
  </code></pre>
  
  <p><strong>Migration for social_accounts_table</strong></p>
  
  <pre><code>class CreateSocialAccountsTable extends Migration { 
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up() {
          Schema::create('social_accounts', function (Blueprint $table) {
              $table-&gt;increments('user_id');
              $table-&gt;string('provider_user_id');
              $table-&gt;string('provider');
              $table-&gt;timestamps();
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down() {
          Schema::dropIfExists('social_accounts');
      }
  }
  </code></pre>
  
  <p><strong>SocialAccountService.php</strong></p>
  
  <pre><code>namespace App;
  
  use Laravel\Socialite\Contracts\User as ProviderUser;
  
  class SocialAccountService {
      public function createOrGetUser(ProviderUser $providerUser) {
          $account = SocialAccount::whereProvider('google')
              -&gt;whereProviderUserId($providerUser-&gt;getId())
              -&gt;first();
  
          if ($account) {
              return $account-&gt;user;
          } else {
              $account = new SocialAccount([
                  'provider_user_id' =&gt; $providerUser-&gt;getId(),
                  'provider' =&gt; 'google'
              ]);
  
              $user = User::whereEmail($providerUser-&gt;getEmail())-&gt;first();
  
              if (!$user) {
                  $user = User::create([
                      'email' =&gt; $providerUser-&gt;getEmail(),
                      'name' =&gt; $providerUser-&gt;getName(),
                      'role' =&gt; 'user',
                      'password' =&gt; '',
                  ]);
              }
  
              $account-&gt;user()-&gt;associate($user);
              $account-&gt;save();
              return $user;
          }
  
      }
  }
  </code></pre>