类型错误:传递给Illuminate \ Auth \ SessionGuard :: login()的参数1必须实现接口Illuminate \ Contracts \ Auth \ Authenticatable

时间:2018-05-26 16:30:57

标签: php laravel

我有下面的控制器允许用户使用laravel auth系统登录,但也可以使用socialite登录facebook。

但是当用户点击按钮时#34;使用Facebook登录"它出现了这个错误:

Type error: Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, string given, called in AuthManager.php on line 292.

用户存储在数据库中但出现该错误。你知道为什么吗?

你知道为什么吗?

class OauthController extends Controller
{

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

    }


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

        $findUser = User::where('email', $userFace->email)->first();

        if($findUser){
            Auth::login($findUser);
        }else{
            $user = new User;
            $user->name = $userFace->name;
            $user->surname = "";
            $user->email = $userFace->email;
            $user->password = bcrypt($user->name);
            $user->save();
            Auth::login($userFace->email);
        }
    }
}

AuthController:

class AuthController extends Controller
{
    public function login(){


        if(\Input::has('code')){

        }


        return \Socialite::with('facebook')->redirect();
    }
}

的LoginController:

class LoginController extends Controller
{

    use AuthenticatesUsers;

    protected $redirectTo = '/';

    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    protected function redirectTo()
    {
        if(Route::getRoutes()->match(Request::create(\URL::previous()))->getName() == "cong.reg") {
            return (Request::create(\URL::previous())->getRequestUri());
        }
        return $this->redirectTo;
    }


}

1 个答案:

答案 0 :(得分:0)

-1