axios withCredentials 自定义发送哪个http cookie

Axios withCredentials customize which http cookie to send

假设您在服务器端设置了 2 个 httpOnly cookie(accesstoken 和 refreshtoken) 你想将 accesstoken 传递给所有的前端请求 但只将 refreshtoken 传递给 /RefreshToken 端点。

我可以在 axios 中看到 withCredential: true 标志允许将所有 httponly cookie 传递到服务器,但是有没有办法将其自定义为特定的 cookie?

httpOnly cookie 不是这样工作的。您无法访问它们或决定从浏览器发送哪些内容。

您的 server-side 路由 /RefreshToken 代码似乎可以很容易地忽略 accessToken cookie 而只关注 refreshToken cookie。这完全取决于您的服务器代码,因此您可以相应地对其进行编码。

but is there a way to customize this to a specific cookie ?

不,不适用于 httpOnly cookie。他们是 httpOnly 是有原因的——客户不能以任何方式惹他们。