问题
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