Kbwebs / MultiAuth

MIT License
138 stars 36 forks source link

Error with custom UserProvider #24

Open Biptaste opened 8 years ago

Biptaste commented 8 years ago

Hi,

I tried to use your package with a custom UserProvider

Argument 1 passed to Kbwebs\MultiAuth\Guard::__construct() must implement interface Illuminate\Contracts\Auth\UserProvider, instance of Illuminate\Auth\Guard given

in Guard->__construct(object(Guard), object(Store), 'user') in AuthManager.php line 47

I registered my UserProvider as written in Laravel's doc (I use Laravel 5.1)

Auth::user()->extend('user', function($app) {
    return $this->app->make(\App\Auth\UserProvider::class);
});

Actually I wrote a dirty fix, I registered my provider like that.

Auth::user()->extend('user', function($app) {
    return new \Kbwebs\MultiAuth\Guard($app->make(\App\Auth\UserProvider::class), $app['session.store'], 'user');
});
tanner0101 commented 8 years ago

I'm also experiencing this issue.

dorianneto commented 8 years ago

Hi guys,

I tried to create a custom EloquentUserProvider about your package and I also had the same problem. I searched for the problem and after some time, I realized that the method callCustomCreator in Kbwebs\MultiAuth\AuthManager class return a Guard type instead of a Provider type.

To resolve this issue, I chained a method getProvider() to return to be a Provider type.

/**
 * Call a custom driver creator.
 * @param  string  $driver
 * @return \Kbwebs\MultiAuth\Guard
 */
protected function callCustomCreator($driver)
{
    $custom = parent::callCustomCreator($driver)->getProvider(); <--------
    if($custom instanceof Guard) {
        return $custom;
    }
    return new Guard($custom, $this->app['session.store'], $this->name);
}

I have not tested to custom DatabaseProvider, that is why I have not sent a PR.

I hope that help.