Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel 5.6 socialite auth by facebook email is null

I use laravel 5.6 and laravel/socialite: "^3.2.0" for auth by Facebook but while login to facebook user email is null (user facebook account has email)

my code for auth :

public function redirectToProvider($provider)
    {
        return Socialite::driver($provider)->redirect();
    }

public function handleProviderCallback($provider)
    {
        $user = Socialite::driver($provider)->user();

        dd($user);
        $authUser = $this->findOrCreateUser($user, $provider);
        Auth::login($authUser, true);
        return redirect($this->redirectTo);
    }

public function findOrCreateUser($user, $provider)
    {
        $authUser = User::where('provider_id', $user->id)->first();
        if ($authUser) {
            return $authUser;
        }

        return User::create([
            'name'     => $user->name,
            'email'    => $user->email,
            'provider' => $provider,
            'provider_id' => $user->id
        ]);
    }


  [1]: https://i.sstatic.net/6zYEI.png
like image 511
saman Avatar asked Oct 27 '25 03:10

saman


1 Answers

Yes, there is no error in your code. There are some additional things you need to enable to solve this problem.

you have to change the email permission from "standard access" to "advanced access".

To enable this permission, you need to enter the in the below URL

https://developers.facebook.com/apps/<app-id>/app-review/permissions/

after changing the permission, you will start receiving the email in the payload.

like image 141
Sachin Saini Avatar answered Oct 29 '25 19:10

Sachin Saini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!