{"record":{"id":"30c953449ed99468","repo":"BookStackApp/BookStack","slug":"errors-social-account-not-used","errorCode":null,"errorMessage":"errors.social_account_not_used","messagePattern":"errors\\.social_account_not_used","errorType":"exception","errorClass":"SocialSignInAccountNotUsed","httpStatus":null,"severity":"error","filePath":"app/Access/SocialAuthService.php","lineNumber":139,"sourceCode":"            session()->flash('error', trans('errors.social_account_existing', ['socialAccount' => $titleCaseDriver]));\n\n            return redirect('/my-account/auth#social_accounts');\n        }\n\n        // When a user is logged in, A social account exists but the users do not match.\n        if ($isLoggedIn && $socialAccount->user->id != $currentUser->id) {\n            session()->flash('error', trans('errors.social_account_already_used_existing', ['socialAccount' => $titleCaseDriver]));\n\n            return redirect('/my-account/auth#social_accounts');\n        }\n\n        // Otherwise let the user know this social account is not used by anyone.\n        $message = trans('errors.social_account_not_used', ['socialAccount' => $titleCaseDriver]);\n        if (setting('registration-enabled') && config('auth.method') !== 'ldap' && config('auth.method') !== 'saml2') {\n            $message .= trans('errors.social_account_register_instructions', ['socialAccount' => $titleCaseDriver]);\n        }\n\n        throw new SocialSignInAccountNotUsed($message, '/login');\n    }\n\n    /**\n     * Get the social driver manager used by this service.\n     */\n    public function drivers(): SocialDriverManager\n    {\n        return $this->driverManager;\n    }\n\n    /**\n     * Fill and return a SocialAccount from the given driver name and SocialUser.\n     */\n    public function newSocialAccount(string $socialDriver, SocialUser $socialUser): SocialAccount\n    {\n        return new SocialAccount([\n            'driver'    => $socialDriver,\n            'driver_id' => $socialUser->getId(),","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/BookStackApp/BookStack/blob/18f8469a1c72f8cc8497e9372635e6dea5028071/app/Access/SocialAuthService.php#L121-L157","documentation":"SocialSignInAccountNotUsed exception thrown when a user completes social LOGIN (/login/service/<driver> callback) but no BookStack user is linked to that social account. Because login and registration are separate flows, BookStack cannot auto-create an account; it builds a message and, if registration is enabled (and auth method is not ldap/saml2), appends instructions to register instead.","triggerScenarios":"User clicks a social login button (e.g. /login/service/google) for an IdP account that has never been registered/linked in this BookStack instance; handleLoginCallback finds no SocialAccount row for the returned driver_id and no matching flow to attach it.","commonSituations":"New employee uses company Google SSO login before an admin created/invited their account; user confuses the 'Login with X' button with 'Register with X'; registration disabled in BookStack so the extra register hint is omitted; auth method switched to ldap/saml2 making social registration unavailable.","solutions":["Register first via /register/service/<driver> (or the Register page) to create and link the account, then use social login","If registration is disabled, ask an admin to enable registration or create/attach the account for you","Double-check you clicked the correct provider button and that you're using the same social account you registered with","If the account should exist, verify the social_accounts table for the driver_id — it may be linked to a different user or a different provider account"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check that the social account is linked before offering login\n$linked = \\BookStack\\Access\\SocialAccount::query()\n    ->where('driver', '=', $driver)\n    ->where('driver_id', '=', $socialUser->getId())\n    ->exists();\nif (!$linked && !(setting('registration-enabled') && !in_array(config('auth.method'), ['ldap', 'saml2']))) {\n    return redirect('/login')->with('error', 'No account is linked to this social login. Please register first or contact an admin.');\n}","typeGuard":null,"tryCatchPattern":"use BookStack\\Exceptions\\SocialSignInAccountNotUsed;\n\ntry {\n    $socialUser = $socialAuth->handleLoginCallback($driver);\n} catch (SocialSignInAccountNotUsed $e) {\n    return redirect('/login')->with('info', $e->getMessage()); // message already includes register instructions when applicable\n}","preventionTips":["Provision/link accounts for new users before announcing SSO availability","Make the Register-with-X entry point discoverable when login-with-X fails for unlinked accounts","Check that registration is enabled if you rely on the built-in register hint in the error message","Remember social registration is disabled under ldap/saml2 auth methods — plan provisioning accordingly"],"tags":["oauth","social-login","login","registration"],"backgroundTag":"social-account-not-found","analyzedSha":"18f8469a1c72f8cc8497e9372635e6dea5028071","analyzedAt":"2026-09-02T19:49:33.068Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}