Check if httponly cookie exists in Javascript

前端 未结 4 1792

As the question says can you find out if a cookie exists within Javascript if it is a HttpOnly? I don\'t need to access the information inside of it, just know it has one.

4条回答
  •  心在旅途
    2020-12-16 15:05

    Whenever you need to check whether the cookie exists or not, you can send a request to the server that requires authentication & check the response. If its something like 401 Unauthorized or 403 Forbidden, then the cookie probably doesn't exist & you can prompt the user for login.

    On the other hand, if the cookie exists, it'll be automatically sent by the browser resulting in a 200 OK response.

提交回复
热议问题