[bug]: Error when the user has already Login with a Provider, but there is no user link to the account
Philrobots opened this issue · comments
Describe the bug
Here is our problem 💥
Once in a while, a user connected with the "Google" provider but the application breaks because the user has already login with the "Google" provider but there is no $user
link to the account for whatever reason, mainly because the user is not found in the database.
Basically, our applications break because the "$account" variable has a user attributes null
.
File : AuthenticateOAuthCallback.php
line 89
It would be great if you could add a verification to verify that the user link to the account is not null.
If the user exists, continue, if not call the register
method.
To Reproduce
Steps to reproduce the behavior:
$account needs to have an attributes user that is null, and to not match in the first condition.
Expected behavior
To add this condition in the authenticate
function
// Add verification
if (!$account->user) {
return $this->register($provider, $providerAccount);
}
// Continues
$user = $account->user;
$this->updatesConnectedAccounts->update($user, $account, $provider, $providerAccount);
return $this->login($user);
Screenshots
![image](https://private-user-images.githubusercontent.com/47373969/281489096-acfd9845-c9a3-4381-beb1-239664404ee8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE5Njc3MDgsIm5iZiI6MTcyMTk2NzQwOCwicGF0aCI6Ii80NzM3Mzk2OS8yODE0ODkwOTYtYWNmZDk4NDUtYzlhMy00MzgxLWJlYjEtMjM5NjY0NDA0ZWU4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI2VDA0MTY0OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWZhOTY5Njg4MTNlNzNmMWRkNDkwNmVhODNkYzE1MWIwODdkMGRjZDgxMGFlNGFkZDJlNmE3NTk3N2YyY2ViNjAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.FqcNTpsY1CBYAi4QAXKkasm7wCFx2vVDLe_oVoLrU5Q)
Environment context
- Socialstream version: 5.2.0
- Jetstream stack: Inertia / Livewire
- PHP version: 8.1.0
After taking a long look at this, I’m pretty sure this is not a bug. You cannot create a connected account instance without first creating the user instance (the user_id
value on the connected_accounts
table should link to the primary ID of a user).
If you have somehow managed to end up in this state, then I assume a user has previously deleted their account and you’ve subsequently not cascaded the deletion down to include any of their connected account relations.
This bug still exists, I have the same issue and no, I dont forget delete on cascade