mercredi 13 février 2019

Socialite can't login via Google

I'm current using Laravel 5.5 and Socialite 2.0 I want to enable user to login via Google and until now I can get user info from google and create new user using the information. However, I can't seem to login with the credential. There is no error message either...Any thoughts? Below is my code

    $user = Socialite::driver('google')->user();


    $existingUser = User::where('email', $user->email)->first();
    if($existingUser){
        // log them in

        Auth::login($existingUser);


    } else {
        // create a new user
        $newUser                  = new User;
        $newUser->name            = $user->name;
        $newUser->email           = $user->email;
        $newUser->google_id       = $user->id;
        $newUser->avatar          = $user->avatar;
        $newUser->avatar_original = $user->avatar_original;
        $newUser->save();
        Auth::login($newUser, true);


    }
    return redirect()->to('/home');



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire