Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target [Laravel\Socialite\Contracts\Factory] is not instantiable on Laravel Socialite v5.16.1 #727

Closed
AsianManiac opened this issue Jan 16, 2025 · 3 comments

Comments

@AsianManiac
Copy link

Socialite Version

5.16.1

Laravel Version

11.31

PHP Version

8.3

Database Driver & Version

MySQL

Description

I’ve encountered an issue with Laravel Socialite version 5.16.1 in production. When using Socialite::driver('google')->redirect() for social login, the application throws the following error:

Error: Target [Laravel\Socialite\Contracts\Factory] is not instantiable.

public function redirect(Request $request, string $driver): RedirectResponse
    {
        try {
            return Socialite::driver($driver)->redirect();
        } catch (\Exception $e) {
            Log::error("Error during social login redirect for {$driver}: " . $e->getMessage());
            return redirect()->route('login')->with('error', 'Unable to connect to ' . ucfirst($driver) . '. Please try again.');
        }
    }

The error occurs despite having the correct configuration in config/services.php for Google. Reverting to Socialite version 5.15.0 resolves the issue, suggesting a regression in the latest version. This breaks social login functionality and disrupts user authentication.
This happens only on production because I didn't face any problems when using the latest version locally.

Steps taken:

  1. Verified Laravel and Socialite versions.
  2. Checked services.php configuration.
  3. Identified the issue doesn’t exist in 5.15.0.

This appears to be a problem with dependency injection for Factory (not completely sure). Would appreciate assistance in resolving this.

Steps To Reproduce

  1. Install Laravel Socialite v5.16.1 using composer require laravel/socialite.
  2. Configure a social driver (e.g., Google) in config/services.php.
  3. Attempt to redirect to the social login page in production using:
    return Socialite::driver('google')->redirect(); but it works locally just fine without issues.
  4. Observe the error: "Target [Laravel\Socialite\Contracts.Factory] is not instantiable."
@crynobone
Copy link
Member

public function register()
{
$this->app->singleton(Factory::class, function ($app) {
return new SocialiteManager($app);
});
}

It is available from the service provider.

@crynobone
Copy link
Member

Hey there, thanks for reporting this issue.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here?

Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

@crynobone
Copy link
Member

Hey there,

We're closing this issue because it's inactive, already solved, old, or not relevant anymore. Feel free to open up a new issue if you're still experiencing this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants