You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用/api/login_check遇无状态Session错误,需保持stateless=true获取JWT

问题解决:stateless=true下调用/api/login_check报Session错误

问题根源

你在login防火墙的json_login配置里开启了remember_me: true,但remember_me功能默认依赖Session存储令牌,而stateless: true会完全禁用Session,两者直接冲突,导致报错。

解决方案

只需要移除json_login中的remember_me: true配置即可,修改后的security.yaml中login部分如下:

firewalls:
    login:
        pattern: ^/api/login
        stateless: true
        json_login:
            check_path: /api/login_check
            # 删除这行配置:remember_me: true
            success_handler: lexik_jwt_authentication.handler.authentication_success
            failure_handler: lexik_jwt_authentication.handler.authentication_failure
    # 其余防火墙配置保持不变

额外注意事项

  • Jest测试发送请求时,要确保是纯JSON格式:请求头设置Content-Type: application/json,请求体包含email和password字段(对应你lexik配置里的user_identity_field和password_path)。
  • 测试请求不要携带Cookie,stateless模式下服务器不会处理会话Cookie,带了反而可能触发不必要的Session逻辑。

内容的提问来源于stack exchange,提问作者mauriau

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 02:42:47