Awesome vid Peter. Very usefull! I was thinking about the retrival of the user via the email we get from socialite. What if the user has different emails on different providers. That would create new user if we had two social providers with different emails. Mayde instead of getting the appUser by provider email, we got the SocialAccount by provider_user_id and then the user of that socialAccount. So instead of $user = User::where('email', $provider_user->email)->first(); we do $socialAccount = SocialAccount::where('provider_user_id', $user->id)->where('provider', $provider)->first(); then $appUser = $socialAccount->user();
Yes, you might do it like that too, but you kinda need to manage things differently after that. Depends on what you really need, it's usually normal if the user register/login with multiple social accounts, to have multiple accounts.. But you can implemente something like that too, if you really need it this way.
@@ProgrammingwithPeter Yes depends on different needs. I ended up implementing that. The reason is , in my case, a user has tickets. So if the social email is different then a new user will be created and his tickets will be empty. I shared my implemantation here -> paste.laravel.io/57ad83eb-083c-4d7d-8772-ab66492c2e9a