@martinbean Thanks for taking the time to clarify. It makes perfect sense.
I'm actually doing what you mentioned with multiple providers:
I'm checking to see if the user exists and then creating or updating based on some assumptions. I probably need to create an interface for this, but if anyone is curious, here's a (very raw) approach using the this schema. Any feedback would be appreciated.
$social = Socialite::driver($provider_name)->user();
// check for existing account via provider uid
$social_profile = SocialProfile::where('uid', $social->id)->first();
if ($social_profile) {
// if profile exists - get the user object
$user = User::find($social_profile->user_id);
} else {
// otherwise check for an existing email address
$user = User::where('email', $social->email)->first();
}
// If we have a user - log them in
if ($user) {
\Auth::login($user);
// Double check the uid on the social_profile
// for the case of a different provider
// if not found add a record
$social_profile = SocialProfile::firstOrCreate([
'user_id' => $user->id,
'provider_id' => $provider_id,
'uid' => $social->id
]);
return redirect('user/profile');
// Profile does not exist - create a new user account
} else {
$user = new User;
$user->name = $social->name;
$user->email = $social->email;
$user->password = bcrypt(substr($social->token, 0, 10));
$user->save();
$social_profile = SocialProfile::firstOrCreate([
'user_id' => $user->id,
'provider_id' => $provider_id,
'uid' => $social->id
]);
\Auth::login($user);
// redirect the user and suggest changing their password
return redirect('user/reset');
}