{"record":{"id":"f8eae0b102bba152","repo":"BookStackApp/BookStack","slug":"errors-social-account-in-use","errorCode":null,"errorMessage":"errors.social_account_in_use","messagePattern":"errors\\.social_account_in_use","errorType":"exception","errorClass":"UserRegistrationException","httpStatus":null,"severity":"error","filePath":"app/Access/SocialAuthService.php","lineNumber":60,"sourceCode":"     */\n    public function startRegister(string $socialDriver): RedirectResponse\n    {\n        $socialDriver = trim(strtolower($socialDriver));\n        $this->driverManager->ensureDriverActive($socialDriver);\n\n        return $this->getDriverForRedirect($socialDriver)->redirect();\n    }\n\n    /**\n     * Handle the social registration process on callback.\n     *\n     * @throws UserRegistrationException\n     */\n    public function handleRegistrationCallback(string $socialDriver, SocialUser $socialUser): SocialUser\n    {\n        // Check social account has not already been used\n        if (SocialAccount::query()->where('driver_id', '=', $socialUser->getId())->exists()) {\n            throw new UserRegistrationException(trans('errors.social_account_in_use', ['socialAccount' => $socialDriver]), '/login');\n        }\n\n        if (User::query()->where('email', '=', $socialUser->getEmail())->exists()) {\n            $email = $socialUser->getEmail();\n\n            throw new UserRegistrationException(trans('errors.error_user_exists_different_creds', ['email' => $email]), '/login');\n        }\n\n        return $socialUser;\n    }\n\n    /**\n     * Get the social user details via the social driver.\n     *\n     * @throws SocialDriverNotConfigured\n     */\n    public function getSocialUser(string $socialDriver): SocialUser\n    {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/BookStackApp/BookStack/blob/18f8469a1c72f8cc8497e9372635e6dea5028071/app/Access/SocialAuthService.php#L42-L78","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Log in with the existing account instead of registering (the social account is already in use)","Use the 'Forgot password' flow or ask an admin to check which user owns that social account via the social_accounts table","If the old account is stale, have an admin detach the social account from the old user, then retry registration","Register with a different social account or standard email/password"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check before driving the registration callback\n$alreadyUsed = \\BookStack\\Access\\SocialAccount::query()\n    ->where('driver_id', '=', $socialUser->getId())\n    ->exists();\nif ($alreadyUsed) {\n    return redirect('/login')->with('error', 'This social account is already linked; please log in instead.');\n}","typeGuard":null,"tryCatchPattern":"use BookStack\\Exceptions\\UserRegistrationException;\n\ntry {\n    $socialUser = $socialAuth->handleRegistrationCallback($driver, $socialUser);\n} catch (UserRegistrationException $e) {\n    if ($e->getMessage() === trans('errors.social_account_in_use', ['socialAccount' => $driver])) {\n        return redirect('/login')->with('info', 'Account already exists — please sign in.');\n    }\n    throw $e;\n}","preventionTips":["Show 'Login with X' as primary once a user has registered with that provider","Detect the duplicate client-side by checking link status before showing the register button","Educate users that re-registering with the same social account is blocked by design","Audit social_accounts rows when migrating or merging BookStack instances"],"tags":["oauth","social-login","registration","duplicate-account"],"backgroundTag":"social-account-already-linked","analyzedSha":"18f8469a1c72f8cc8497e9372635e6dea5028071","analyzedAt":"2026-09-02T19:49:33.068Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}