Type error: Argument 1 passed to IlluminateAuthSessionGuard::login() must implement interface IlluminateContractsAuthAuthenticatable

I have the controllers below to allow the user login with laravel auth system but also to login with facebook using socialite.

But when the user clicks in the button “Login with facebook” it appears this error:

Type error: Argument 1 passed to IlluminateAuthSessionGuard::login() must implement interface IlluminateContractsAuthAuthenticatable, string given, called in AuthManager.php on line 292.

The user is stored in the database but that error appears. Do you know why?

Do you know why?

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;
    }


}

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

try

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

Method 2

class AuthController extends Controller
{

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

}


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

correct spellings of AuthController and use it.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x