0

I am using socialite in my project. it is working fine in local environment but when i have switched to production environment it is not working anymore. Sign in with google redirects me back again to "sign in " page of google. i have updated the callback url in google api settings. please help

    public function handleProviderCallback($provider)
    {
    try 
    {
        $socialUser = Socialite::driver($provider)->user();
    } 
    catch (\Exception $e) 
    {
        return back()->withErrors([

            'socialConnectionError', 'An error has occured while connecting to '.$provider.' service'

            ]);
    }

    $socialProvider = SocialProvider::where('provider_id', $socialUser->getId())->first();

    if (! $socialProvider) {

        $user = User::firstOrCreate([

            'is_activated' => 1,
            'email'        => $socialUser->getEmail(),
            'name'         => $socialUser->getName()

            ]);

        // still needs to implement the system where a user may change its name and email on social provider

        $user->socialProviders()->create(

                ['provider_id'  => $socialUser->getId(),
                'provider'      => $provider]
            );

    }
    else
    {
        $user = $socialProvider->user;
    }

    auth()->login($user);

    return redirect($this->redirectPath());
}


public function redirectToProvider($provider)
{
    return Socialite::driver($provider)->redirect();
}
Ahmed Nawaz Khan
  • 1,451
  • 3
  • 20
  • 42

0 Answers0