{"record":{"id":"6b37ca5119704de8","repo":"BookStackApp/BookStack","slug":"errors-error-user-exists-different-creds-6b37ca","errorCode":null,"errorMessage":"errors.error_user_exists_different_creds","messagePattern":"errors\\.error_user_exists_different_creds","errorType":"exception","errorClass":"UserRegistrationException","httpStatus":null,"severity":"error","filePath":"app/Access/SocialAuthService.php","lineNumber":66,"sourceCode":"        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    {\n        $socialDriver = trim(strtolower($socialDriver));\n        $this->driverManager->ensureDriverActive($socialDriver);\n\n        return $this->socialite->driver($socialDriver)->user();\n    }\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/BookStackApp/BookStack/blob/18f8469a1c72f8cc8497e9372635e6dea5028071/app/Access/SocialAuthService.php#L48-L84","documentation":"UserRegistrationException thrown during social registration callback when no social account matches but a BookStack user with the same email address already exists. Registration with the social identity would create a duplicate account, so the flow aborts with errors.error_user_exists_different_creds, telling the user that email is registered with different credentials.","triggerScenarios":"User attempts /register/service/<driver> with a social account whose email equals the email of an existing BookStack user that was created via email/password (or a different auth method), and no social_accounts row exists for this driver_id.","commonSituations":"User registered earlier with email+password then tries to sign up via Google/GitHub using the same address; admin pre-created the user with the same email; email changed at the IdP to collide with an existing local account.","solutions":["Log in with the original credentials (email/password) instead of registering via the social provider","Once logged in, attach the social account to the existing user via profile 'External authentication' / social connector settings","Use password reset if the original password is forgotten, then link the social account","Admin can verify/merge accounts in the users admin section"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check email collision before the registration callback\n$emailTaken = \\BookStack\\Users\\User::query()\n    ->where('email', '=', $socialUser->getEmail())\n    ->exists();\nif ($emailTaken) {\n    return redirect('/login')->with('info', 'An account with this email already exists. Log in and link the social account from your profile.');\n}","typeGuard":null,"tryCatchPattern":"use BookStack\\Exceptions\\UserRegistrationException;\n\ntry {\n    $socialUser = $socialAuth->handleRegistrationCallback($driver, $socialUser);\n} catch (UserRegistrationException $e) {\n    if (str_contains($e->getMessage(), trans('errors.error_user_exists_different_creds', ['email' => $socialUser->getEmail()]))) {\n        return redirect('/login')->with('info', 'Email already registered with another method — please log in and link your account.');\n    }\n    throw $e;\n}","preventionTips":["Encourage users to log in with existing credentials and link social accounts from their profile rather than re-registering","Offer a visible password-reset link on the register page to route users with existing emails to login","Keep the local user email and IdP email consistent to avoid collisions when SSO is rolled out","During user provisioning, pre-link social accounts so registration attempts aren't needed"],"tags":["oauth","social-login","registration","email-conflict"],"backgroundTag":"email-already-registered","analyzedSha":"18f8469a1c72f8cc8497e9372635e6dea5028071","analyzedAt":"2026-09-02T19:49:33.068Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}