{"id":"76075dd8ec67e636","repo":"laravel/framework","slug":"cookie-jar-has-not-been-set","errorCode":null,"errorMessage":"Cookie jar has not been set.","messagePattern":"Cookie jar has not been set\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Auth/SessionGuard.php","lineNumber":932,"sourceCode":"     */\n    public function setRememberDuration($minutes)\n    {\n        $this->rememberDuration = $minutes;\n\n        return $this;\n    }\n\n    /**\n     * Get the cookie creator instance used by the guard.\n     *\n     * @return \\Illuminate\\Contracts\\Cookie\\QueueingFactory\n     *\n     * @throws \\RuntimeException\n     */\n    public function getCookieJar()\n    {\n        if (! isset($this->cookie)) {\n            throw new RuntimeException('Cookie jar has not been set.');\n        }\n\n        return $this->cookie;\n    }\n\n    /**\n     * Set the cookie creator instance used by the guard.\n     *\n     * @param  \\Illuminate\\Contracts\\Cookie\\QueueingFactory  $cookie\n     * @return void\n     */\n    public function setCookieJar(CookieJar $cookie)\n    {\n        $this->cookie = $cookie;\n    }\n\n    /**\n     * Get the event dispatcher instance.","sourceCodeStart":914,"sourceCodeEnd":950,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Auth/SessionGuard.php#L914-L950","documentation":"Thrown by SessionGuard::getCookieJar() when the cookie jar was never injected. The guard needs it to queue/read remember-me cookies during login/logout and logoutOtherDevices(); createSessionDriver() normally calls setCookieJar() for you.","triggerScenarios":"Instantiating a SessionGuard manually (or via a custom driver) and invoking login()/logout()/logoutOtherDevices() without calling setCookieJar(); using a session guard inside a queue worker or console command where the 'cookie' binding is absent.","commonSituations":"Running authentication flows in a job/worker/test where the HTTP kernel did not boot the cookie middleware; custom guard setup that bypasses AuthManager::createSessionDriver(); mocking the guard and forgetting the cookie dependency.","solutions":["Resolve the guard through Auth::guard() (or auth()) so AuthManager::createSessionDriver() wires the cookie jar.","If you construct the guard manually, call $guard->setCookieJar(app('cookie')).","Avoid remember-me/login flows inside queue workers; if needed, bind a cookie factory first.","In tests, use Illuminate\\Foundation\\Testing\\TestCase which boots the HTTP stack."],"exampleFix":"// before\n$guard = new \\Illuminate\\Auth\\SessionGuard('web', $provider, app('session.store'));\n$guard->login($user); // throws - no cookie jar\n\n// after\n$guard = new \\Illuminate\\Auth\\SessionGuard('web', $provider, app('session.store'));\n$guard->setCookieJar(app('cookie'));\n$guard->setDispatcher(app('events'));\n$guard->login($user);","handlingStrategy":"validation","validationCode":"$guard = Auth::guard('web');\nif (! method_exists($guard, 'getCookieJar') || ! app()->bound('cookie')) {\n    throw new RuntimeException('Session guard requires a cookie jar; resolve via Auth::guard() in an HTTP context.');\n}","typeGuard":"function guardHasCookieJar($guard): bool\n{\n    try {\n        return $guard instanceof \\Illuminate\\Auth\\SessionGuard\n            && app()->bound('cookie');\n    } catch (\\Throwable) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    Auth::guard('web')->login($user, true);\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'Cookie jar has not been set')) {\n        Auth::guard('web')->setCookieJar(app('cookie'));\n        Auth::guard('web')->login($user, true);\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Always resolve session guards through Auth::guard()/auth() so the manager wires the cookie jar.","Do not run login/logout flows inside queue workers; if unavoidable, bind the cookie factory first.","In tests, boot the full HTTP kernel (use Illuminate\\Foundation\\Testing\\TestCase)."],"tags":["authentication","cookie","session","configuration","laravel"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}