Skip to content
Advertisement

Argument passed to (Symfony) Response::setContent() must be of the type string or null, object given

I try to sign up by Facebook, using Laravel 7 and package (Socialite), when press on the URL:

<div class="form-group row mb-0">
     <div class="col-md-6 offset-md-4">
          <a href="{{url('redirect/facebook')}}">login with your facebook account</a>
     </div>
</div>

The redirect page runs the app, i created in facebook developers as the img:

enter image description here

when press (continue as Mahmoud) and put my email and pass this error shows:

TypeError Argument 1 passed to SymfonyComponentHttpFoundationResponse::setContent() must be of the type string or null, object given, called in C:wamp64wwwStartervendorlaravelframeworksrcIlluminateHttpResponse.php on line 65

and URL upove chrom box the following:

http://localhost:8000/callback/facebook?code=AQDlnu6qDKxTV6nG_vN4DYMKSyVP-zEKTL_uJDKbENBTc-pBwtIxpLRkcUS_zebL3nbPo8RjKKC3D_UbZkHM8dz5iZU8c4-PPPdyS_teoLZZ77kVf1pLGCx0ggTwx0EJys8nK3aPE8BugkbgcXTFUt7qcDxQcX1ptlmG9_0qSbuifaEg678bl71Gbm3qU5Jx-_ZsonmuadY3kHTbq8vG-3s2jqV4KkxDSCw-m-4LrIe46v73EXFzG1wFNMbkWB4MJay5ZewPjI2ah3p8o5FCgGLp1Rs4clsKW5B2fQyoWc6MM-Ut2jESoQ7YMOjZpuX5kA1aWP3To1TncAjKpWsAevIa&state=n0XP5Kf68IZlOUqm1pwUYryb9md9nHCdSnatvbpO#_=_

my Routes:

Route::get('/redirect/{service}','SocialiteController@redirect');
Route::get('/callback/{service}','SocialiteController@callback');

Controller:

    <?php

namespace AppHttpControllers;

use IlluminateHttpRequest;
use LaravelSocialiteFacadesSocialite;

class SocialiteController extends Controller
{
    public function redirect($service){
        return Socialite::driver($service)->redirect();

    }
    public function callback($service){

         $user = Socialite::with($service) -> user();
         return $user;

    }

}

.env:

FB_CLIENT_ID = XXX
FB_CLIENT_SECRET = XXX
FB_REDIRECT = 'http://localhost:8000/callback/facebook'

config/services.php:

 'facebook' => [
    'client_id' => env ('FB_CLIENT_ID'),
    'client_secret' => env ('FB_CLIENT_SECRET'),
    'redirect' => env ('FB_REDIRECT')
],

in config/app.php i added:

LaravelSocialiteSocialiteServiceProvider::class,

and

'Socialite' => LaravelSocialiteFacadesSocialite::class,

please could you help me i try lot of solutions but no way.

Advertisement

Answer

i should return a Response instead of the $user object in controller

change

public function callback($service){

     $user = Socialite::with($service) -> user();
     return $user;

}

to

        public function callback($service){
           $user = Socialite::with($service)->stateless()->user();
           return response()->json($user);
    
        }
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement