{"record":{"id":"2a0daaddee984399","repo":"flarum/framework","slug":"use-of-accesstoken-generate-is-not-allowed-use-the-generate","errorCode":null,"errorMessage":"Use of AccessToken::generate() is not allowed: use the `generate` method on one of the subclasses.","messagePattern":"Use of AccessToken::generate\\(\\) is not allowed: use the `generate` method on one of the subclasses\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"framework/core/src/Http/AccessToken.php","lineNumber":92,"sourceCode":"    private const LAST_ACTIVITY_UPDATE_DIFF = 90;\n\n    public ?array $uniqueKeys = ['token'];\n\n    /**\n     * Generate an access token for the specified user.\n     */\n    public static function generate(int $userId): static\n    {\n        $token = static::make($userId);\n        $token->save();\n\n        return $token;\n    }\n\n    public static function make(int $userId): static\n    {\n        if (static::class === self::class) {\n            throw new \\Exception('Use of AccessToken::generate() is not allowed: use the `generate` method on one of the subclasses.');\n        }\n\n        $token = new static;\n        $token->type = static::$type;\n        $token->token = Str::random(40);\n        $token->user_id = $userId;\n        $token->created_at = Carbon::now();\n        $token->last_activity_at = Carbon::now();\n\n        return $token;\n    }\n\n    /**\n     * Update the time of last usage of a token.\n     * If a request object is provided, the IP address and User Agent will also be logged.\n     */\n    public function touch($attribute = null, ?ServerRequestInterface $request = null): bool\n    {","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/flarum/framework/blob/4b939f685389bfe8a380e9e28ddf305a1c66950c/framework/core/src/Http/AccessToken.php#L74-L110","documentation":"Sentinel guard in AccessToken::make: calling make()/generate() directly on the base AccessToken class is forbidden because the base class has no token type (static::$type is undefined for it). Tokens must be created via a concrete subclass (e.g. DeveloperAccessToken, Rememberer) so the 'type' column is set correctly. Calling AccessToken::generate() lands in make() with static::class === AccessToken::class and throws.","triggerScenarios":"Thrown at framework/core/src/Http/AccessToken.php:92 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call generate() on a concrete subclass, e.g. DeveloperAccessToken::generate($userId)","Choose the appropriate token subclass for the lifetime/purpose you need","Type-hint against the subclass you intend to issue rather than AccessToken"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4b939f685389bfe8a380e9e28ddf305a1c66950c","analyzedAt":"2026-09-15T18:09:20.879Z","contentChangedAt":"2026-09-15T18:09:20.879Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}