abduljakul-salsalani's avatar

Laravel Socialite Error: This site can’t be reached localhost unexpectedly closed the connection.

Chrome suddenly gives me an error that says :

This site cant be reached localhost unexpectedly closed the connection. ERR_CONNECTION_CLOSED

after facebook redirects me to this route:

Route::get('login/{provider}/callback', 'AuthSocialController@handle_provider_callback');

I don't know why I keep no experiencing this error :

public function handle_provider_callback()
{   
    // return Socialite::with('facebook')->user(); 
    
    $getInfo = Socialite::driver($provider)->user(); 
    $user = $this->createUser($getInfo,$provider); 
    auth()->login($user); 
    return redirect()->to('/home');
}

and this is the createUser() method:

function createUser($getInfo,$provider){
    
    $user = User::where('provider_id', $getInfo->id)->first();
    
    if (!$user) {
        $user = User::create([
            'first_name'     =>  $getInfo->first_name,
            'last_name'  =>   $getInfo->last_name,
            'email'    =>        $getInfo->email,
            'provider' =>        $provider,
            'provider_id' =>     $getInfo->id
        ]);
    }

    return $user;
}```
0 likes
11 replies
munazzil's avatar

Change handle_provider_callback function as like below,

     public function handle_provider_callback()
           {   
               $getInfo = Socialite::driver($provider)->auth()->user();
               $user = $this->createUser($getInfo,$provider); 
               
               return redirect()->to('/home');
           }
munazzil's avatar

Then it could be cache error try below commands in CMD,

       php artisan cache:clear
       php artisan view:clear
       php artisan route:clear
       php artisan config:clear
abduljakul-salsalani's avatar

I get this in my console :

[Fri Oct 4 3:27:11 2019] 127.0.0.1:53209 Invalid request (Unsupported SSL request)

munazzil's avatar

Can you show your .env file and also config/app?

abduljakul-salsalani's avatar
APP_ENV=local
APP_KEY=base64:0lKLGVJe+p5dMIpLnTIp3Dzxxxxxxxxxx
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1   
DB_PORT=3306
DB_DATABASE=ad-manager
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=log
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

FACEBOOK_APP_ID=63746xxxxxxxx
FACEBOOK_ACCESS_KEY=546def8f5313d237axxxxxxxxxxxx
FACEBOOK_MARKETING_API=
FACEBOOK_REDIRECT=http://localhost:8900/login/facebook/callback
    
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
Vitha's avatar

i am also encounter this situation. have you got the solution for this error?

Please or to participate in this conversation.