Axios: How to check for cookie in browser before sending API request?

試著忘記壹切 提交于 2020-08-10 22:47:13

问题


Goal: In the browser code, check that a cookie is present before sending a specific request that always requires credentials.

The cookie contains a JWT token.

Other Details:

  • Vue.js (used for front-end code in browser)
  • Axios (used for all API calls to back-end API)
  • JWT Token (inside the cookie)
  • Cookie set with "http-only" by the server that creates it

Checking for cookie existence prior to sending a request is good. It would be even better to check if the cookie containing the JWT token is expired and be able to delete it if so.

I've taken a look at other posts, including the "definitive guide to form based website authentication" (The definitive guide to form-based website authentication), among others, but they do not address anything about interacting with cookies in the browser code.

Is it possible to use an Axios interceptor to check for existence of credentials in config prior to sending the request?

来源:https://stackoverflow.com/questions/63246371/axios-how-to-check-for-cookie-in-browser-before-sending-api-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!