From ce41f35f280267f51f2fd555c413c096e3b8d6a1 Mon Sep 17 00:00:00 2001 From: luishou Date: Mon, 13 Jul 2026 16:21:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(auth):=20=E9=80=80=E5=87=BA=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=81=BF=E5=85=8D=E8=B7=B3=E8=BD=AC=E5=88=B0=200.0.0.?= =?UTF-8?q?0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit signOut 改用 redirect:false 后由浏览器同源跳转 /login,并明确生产 AUTH_URL 不得写成监听地址 0.0.0.0。 Co-Authored-By: Claude --- .env.example | 4 +++- DEPLOY.md | 10 +++++++--- src/components/app/topbar.tsx | 8 +++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index e56c8d9..6d3eaa3 100644 --- a/.env.example +++ b/.env.example @@ -5,6 +5,8 @@ DATABASE_URL="mysql://crm_dev:PASSWORD@124.223.187.95:3306/crm_dev" AUTH_SECRET="please-run-openssl-rand-base64-32" # 开发环境不需要 AUTH_URL(trustHost:true 自动识别 host/端口)。 -# 仅生产部署时设为真实域名: +# 生产必须设为浏览器可访问的地址(真实域名或公网 IP), +# 切勿写成监听地址 0.0.0.0,否则登录/退出会跳到 http://0.0.0.0:端口 # AUTH_URL="https://crm.yourdomain.com" +# AUTH_URL="http://124.223.187.95:3100" diff --git a/DEPLOY.md b/DEPLOY.md index 0cbbcde..df76c69 100644 --- a/DEPLOY.md +++ b/DEPLOY.md @@ -41,10 +41,14 @@ DATABASE_URL="mysql://用户:密码@数据库内网IP:3306/crm?connection_limit= # 会话密钥:openssl rand -base64 32 AUTH_SECRET="<生成的随机串>" -# 生产站点地址(真实域名或 http://公网IP:3100) -AUTH_URL="https://crm.yourdomain.com" +# 生产站点地址(浏览器访问的真实域名或公网 IP,不要写 0.0.0.0) +# -H 0.0.0.0 只是监听网卡;AUTH_URL 必须是用户打开的那个地址 +AUTH_URL="http://124.223.187.95:3100" +# 有域名时改成: +# AUTH_URL="https://crm.yourdomain.com" ``` > `.env` 由 Next 在 `next start` 时自动加载,PM2 无需重复配置这些变量。 +> **`AUTH_URL` 写错成 `http://0.0.0.0:3100` 会导致退出登录跳到 `0.0.0.0`。** --- @@ -172,5 +176,5 @@ npx prisma generate | 登录报 Configuration / PrismaClientInitializationError | 连不上数据库:检查 `DATABASE_URL`、内网连通、连接池参数 | | 上传 Excel 失败 | Nginx `client_max_body_size` 太小;应用侧已放宽到 10mb | | 老账号登不上 | 无需处理,`$2y$` bcrypt 密码由应用直接校验,原样可登录 | -| 退出/跳转到错误地址 | 生产必须设 `AUTH_URL` 为真实域名或 `http://公网IP:3100` | +| 退出跳到 `http://0.0.0.0:3100/login` | `AUTH_URL` 未设或写成了监听地址 `0.0.0.0`。改为 `http://公网IP:3100` 或真实域名后 `pm2 restart liandong-crm`;与 `-H 0.0.0.0` 无关 | | PM2 重启后进程没了 | 忘了 `pm2 save` + `pm2 startup` | diff --git a/src/components/app/topbar.tsx b/src/components/app/topbar.tsx index 6bb8732..9581292 100644 --- a/src/components/app/topbar.tsx +++ b/src/components/app/topbar.tsx @@ -78,7 +78,13 @@ export function Topbar({ 个人中心