joelbutcher / socialstream

OAuth for Laravel, simplified.

Home Page:https://docs.socialstream.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[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

image

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

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