{"record":{"id":"35d3c196e8a884fd","repo":"Leantime/leantime","slug":"user-must-be-authenticated-to-create-token","errorCode":null,"errorMessage":"User must be authenticated to create token","messagePattern":"User must be authenticated to create token","errorType":"exception","errorClass":"\\Exception","httpStatus":null,"severity":"error","filePath":"app/Domain/Auth/Services/Auth.php","lineNumber":254,"sourceCode":"\n            self::dispatch_event('afterLoginCheck', ['username' => $username, 'password' => $password, 'authService' => app()->make(self::class)]);\n\n            return true;\n        } else {\n            $this->logFailedLogin($username);\n            self::dispatch_event('afterLoginCheck', ['username' => $username, 'password' => $password, 'authService' => app()->make(self::class)]);\n\n            return false;\n        }\n    }\n\n    /**\n     * Create a new personal access token\n     */\n    public function createToken(string $name, array $abilities = ['*']): array\n    {\n        if (! $this->loggedIn()) {\n            throw new \\Exception('User must be authenticated to create token');\n        }\n\n        return $this->tokenRepo->createToken($this->getUserId(), $name, $abilities);\n    }\n\n    /**\n     * @return false|void\n     *\n     * @throws BindingResolutionException\n     */\n    public function setUserSession(mixed $user, bool $isExternalAuth = false)\n    {\n        if (! $user || ! is_array($user)) {\n            return false;\n        }\n\n        // Web-login session. twoFAVerified: false — the web flow enforces interactive 2FA via the\n        // AuthCheck gate. Built via the shared factory (role NAME string + consistent fields), with","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/Leantime/leantime/blob/9a9f49f1008f4782b30f6723c54228f4f992e636/app/Domain/Auth/Services/Auth.php#L236-L272","documentation":"Error \"User must be authenticated to create token\" thrown in Leantime/leantime.","triggerScenarios":"Thrown at app/Domain/Auth/Services/Auth.php:254 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9a9f49f1008f4782b30f6723c54228f4f992e636","analyzedAt":"2026-08-21T02:37:38.966Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}