BookStackApp/BookStack · error · UserRegistrationException

errors.social_account_in_use

Error message

errors.social_account_in_use

What it means

UserRegistrationException thrown during social (OAuth) registration callback when the social account ID being registered is already linked to a BookStack user. handleRegistrationCallback first checks the social_accounts table for the driver_id and rejects duplicates so one social identity cannot be attached twice.

Source

Thrown at app/Access/SocialAuthService.php:60

     */
    public function startRegister(string $socialDriver): RedirectResponse
    {
        $socialDriver = trim(strtolower($socialDriver));
        $this->driverManager->ensureDriverActive($socialDriver);

        return $this->getDriverForRedirect($socialDriver)->redirect();
    }

    /**
     * Handle the social registration process on callback.
     *
     * @throws UserRegistrationException
     */
    public function handleRegistrationCallback(string $socialDriver, SocialUser $socialUser): SocialUser
    {
        // Check social account has not already been used
        if (SocialAccount::query()->where('driver_id', '=', $socialUser->getId())->exists()) {
            throw new UserRegistrationException(trans('errors.social_account_in_use', ['socialAccount' => $socialDriver]), '/login');
        }

        if (User::query()->where('email', '=', $socialUser->getEmail())->exists()) {
            $email = $socialUser->getEmail();

            throw new UserRegistrationException(trans('errors.error_user_exists_different_creds', ['email' => $email]), '/login');
        }

        return $socialUser;
    }

    /**
     * Get the social user details via the social driver.
     *
     * @throws SocialDriverNotConfigured
     */
    public function getSocialUser(string $socialDriver): SocialUser
    {

View on GitHub (pinned to 18f8469a1c)

Solutions

  1. Log in with the existing account instead of registering (the social account is already in use)
  2. Use the 'Forgot password' flow or ask an admin to check which user owns that social account via the social_accounts table
  3. If the old account is stale, have an admin detach the social account from the old user, then retry registration
  4. Register with a different social account or standard email/password
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check before driving the registration callback
$alreadyUsed = \BookStack\Access\SocialAccount::query()
    ->where('driver_id', '=', $socialUser->getId())
    ->exists();
if ($alreadyUsed) {
    return redirect('/login')->with('error', 'This social account is already linked; please log in instead.');
}

Try / catch

use BookStack\Exceptions\UserRegistrationException;

try {
    $socialUser = $socialAuth->handleRegistrationCallback($driver, $socialUser);
} catch (UserRegistrationException $e) {
    if ($e->getMessage() === trans('errors.social_account_in_use', ['socialAccount' => $driver])) {
        return redirect('/login')->with('info', 'Account already exists — please sign in.');
    }
    throw $e;
}

Prevention

When it happens

Trigger: User clicks 'Register with <socialDriver>' (e.g. /register/service/github) while that GitHub/Google/Okta account's driver_id already exists in the social_accounts table — i.e. the same external identity was previously connected to a BookStack account.

Common situations: User forgot they already registered with that social account; user registered on another BookStack instance sharing the same social app credentials? no — more commonly: user tries to register again after already linking, or uses a shared/team social account that someone already connected.

Related errors


AI-assisted analysis of BookStackApp/BookStack@18f8469a1c (2026-09-02). Data as JSON: /api/errors/f8eae0b102bba152. Report an issue: GitHub.