diff options
author | Sunil Shetye | 2024-03-12 23:30:55 +0530 |
---|---|---|
committer | Sunil Shetye | 2024-03-12 23:42:01 +0530 |
commit | d8ed89ee6e6bfbbb8d568305ed6b797a21be23e2 (patch) | |
tree | ee3f3a8a40de4460e51eb94029a1dcfdb2245294 | |
parent | c483414730666fe93771852a7324cbfc61fc4aca (diff) | |
download | Common-Interface-Project-d8ed89ee6e6bfbbb8d568305ed6b797a21be23e2.tar.gz Common-Interface-Project-d8ed89ee6e6bfbbb8d568305ed6b797a21be23e2.tar.bz2 Common-Interface-Project-d8ed89ee6e6bfbbb8d568305ed6b797a21be23e2.zip |
code for csrftoken
-rw-r--r-- | blocks/eda-frontend/src/utils/Api.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/blocks/eda-frontend/src/utils/Api.js b/blocks/eda-frontend/src/utils/Api.js index cff6288e..983cd013 100644 --- a/blocks/eda-frontend/src/utils/Api.js +++ b/blocks/eda-frontend/src/utils/Api.js @@ -1,9 +1,36 @@ // Creating a new instance of axios for custom API config. import axios from 'axios' +const getCookie = (name) => { + let cookieValue = null + + if (document.cookie && document.cookie !== '') { + const cookies = document.cookie.split(';') + for (let i = 0; i < cookies.length; i++) { + const cookie = cookies[i].trim() + + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) === (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)) + + break + } + } + } + + return cookieValue +} + +const csrftoken = getCookie('csrftoken') + export default axios.create({ baseURL: '/api/', responseType: 'json', xsrfCookieName: 'csrftoken', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + 'X-CSRFToken': csrftoken + }, withCredentials: true }) |