为什么响应看起来正常,Set-Cookie 仍然会失败
当登录后的认证 Cookie 看似“消失”时,这份指南帮助你区分后端响应成功与浏览器 Cookie 策略拒收之间的差别。
即使接口返回了 200 OK,浏览器里的认证会话仍然可能没有真正建立起来。这也是 Cookie 排查最让人困惑的地方:后端认为登录成功了,但浏览器可能悄悄拒收了 Cookie、把它限制到了错误的作用域,或者根本没有在当前上下文里保存它。
真正有效的做法,不是继续盯着成功状态码,而是先看原始 Set-Cookie 行,再把问题拆成头部策略错误、跨域传递问题和令牌内容假设三层来检查。
只有在确认存储成功之后,再看令牌内容
当浏览器已经能把 Cookie 存下来,但会话依旧失败时,才值得去解码其中的 token 或 session payload。此时过期时间、issuer 或 claim 不匹配,才可能是真正的认证失败原因。
这个顺序非常重要,因为即使被浏览器拒收的 Cookie 里放着完全有效的 JWT,登录流程依然是坏的。
本节相关工具
Set-Cookie Header Inspector
Inspect raw Set-Cookie response headers, surface effective attributes, and flag browser policy issues such as SameSite=None without Secure.
CORS Header Checker
Check whether a browser request will pass CORS based on the request method, custom headers, credentials mode, and the response headers your API returns.
JWT Decoder
Decode and inspect JWT tokens instantly to view headers, payloads, and expiration status locally in your browser.