Mahmoud Diab
Mahmoud Diab

Reputation: 551

Argument 1 passed to Symfony\Component\HttpFoundation\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 Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given, called in C:\wamp64\www\Starter\vendor\laravel\framework\src\Illuminate\Http\Response.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 App\Http\Controllers;

use Illuminate\Http\Request;
use Laravel\Socialite\Facades\Socialite;

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 = FB_ID
FB_CLIENT_SECRET = FB_secret
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:

Laravel\Socialite\SocialiteServiceProvider::class,

and

'Socialite' => Laravel\Socialite\Facades\Socialite::class,

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

Upvotes: 2

Views: 11995

Answers (2)

killlinuxkill
killlinuxkill

Reputation: 347

Try:

public function callback($service){
    $user = Socialite::with($service) -> user();
    return (array)$user;
}

Upvotes: 0

Mahmoud Diab
Mahmoud Diab

Reputation: 551

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);
    
        }

Upvotes: 5

Related Questions