From 83773ef54ed0db03b1a22009e0df338345017725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=96=BB=E5=8B=87=E7=A5=A5?= <237899745@qq.com> Date: Fri, 21 Nov 2025 16:42:37 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E8=B7=A8=E5=9F=9FCookie=E4=BC=A0=E9=80=92?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 问题描述 验证码在生产环境(https://cs.workyai.cn)一直提示"验证码已过期" ## 根本原因 axios默认不携带credentials(包括cookies),导致: 1. 验证码生成时的session cookie无法被浏览器保存 2. 登录时无法读取到验证码session 3. SessionID不一致导致验证失败 ## 修复方案 在mounted钩子中添加axios全局配置: ```javascript axios.defaults.withCredentials = true; ``` 这样所有axios请求都会携带cookies,包括: - 验证码生成请求 - 登录验证请求 - 所有其他API请求 ## 配合后端配置 后端已配置: - CORS: credentials: true - Session cookie: sameSite: 'lax' - Session: saveUninitialized: true ## 测试说明 1. 清除浏览器Cookie 2. 访问 https://cs.workyai.cn 3. 输错密码2次触发验证码 4. 输入验证码应该能正常通过 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- frontend/app.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/app.js b/frontend/app.js index 5e119cb..ae7e6fb 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -2131,9 +2131,12 @@ handleDragLeave(e) { }, mounted() { + // 配置axios全局设置 - 确保验证码session cookie正确传递 + axios.defaults.withCredentials = true; + // 初始化调试模式状态 this.debugMode = localStorage.getItem('debugMode') === 'true'; - + // 阻止全局拖拽默认行为(防止拖到区域外打开新页面) window.addEventListener("dragover", (e) => { e.preventDefault();