Search code examples
laravel-7laravel-socialite

Login social with laravel socialite create password


How to inclues password after login with social network with laravel socialite? (sorry for bad english) Com criar/incluir senha fazendo login a partir de uma rede social com o laravel socialite?

code on my LoginController

public function handleProviderCallback($provider)
{
    $user = Socialite::driver($provider)->stateless()->user();
    $authUser = $this->findOrCreateUser($user, $provider);
    Auth::login($authUser, true);
    return redirect($this->redirectTo);
    //return $user->token;
    //dd($userSocial);
}

public function findOrCreateUser($user, $provider)
{
    $authUser = User::where('provider_id', $user->id)->first();
    if ($authUser){
        return $authUser;
    }
    return User::create([
        'name'          => $user->name,
        'email'         => $user->email,
        'provider'      => strToUpper($provider),
        'provider_id'   => $user->id
    ]);
}

Solution

    • In the socialite flow, a user will never need a password
    • You can set password to nullable() in the users migration file.
    • In 'Account Settings' a user can set a password, leaving the current password empty
    • Once the password is set, a socialite user can login via both social media or direct