From 9f71cda86b350406d0cd8e2ebe17e8f8b9b6aa0a Mon Sep 17 00:00:00 2001 From: kurpfish Date: Wed, 4 Aug 2021 17:27:09 +0300 Subject: [PATCH] auth header and env setup --- .gitignore | 1 + package-lock.json | 13 +++++++++---- package.json | 3 ++- src/server/server.js | 27 +++++++++++++++++++++------ 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 4d29575d..8070e751 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ # production /build +.env # misc .DS_Store diff --git a/package-lock.json b/package-lock.json index d2300c63..3b4d2ac1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5350,9 +5350,9 @@ } }, "dotenv": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz", - "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==" + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", + "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==" }, "dotenv-expand": { "version": "5.1.0", @@ -12872,6 +12872,11 @@ "workbox-webpack-plugin": "5.1.4" }, "dependencies": { + "dotenv": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz", + "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==" + }, "sass-loader": { "version": "10.2.0", "resolved": "https://registry.npmjs.org/sass-loader/-/sass-loader-10.2.0.tgz", @@ -16895,4 +16900,4 @@ "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==" } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index f81593a1..8abc5d7a 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "@testing-library/react": "^11.2.7", "@testing-library/user-event": "^12.8.3", "bootstrap": "^4.6.0", + "dotenv": "^10.0.0", "eslint": "^7.27.0", "form-data": "^4.0.0", "moment": "^2.29.1", @@ -47,4 +48,4 @@ "last 1 safari version" ] } -} \ No newline at end of file +} diff --git a/src/server/server.js b/src/server/server.js index 9b7a5678..05f019ef 100644 --- a/src/server/server.js +++ b/src/server/server.js @@ -1,6 +1,10 @@ export const fetchProfile = async (link, index) => { try { - const response = await fetch(`${link}${index}`) + const response = await fetch(`${link}${index}`, { + headers: { + 'Authorization': `Bearer ${localStorage.getItem('auth_token')}` + } + }) let data = await response.json() return data @@ -9,7 +13,11 @@ export const fetchProfile = async (link, index) => { export const fetchSkills = async (link) => { try { - const response = await fetch(link) + const response = await fetch(link, { + headers: { + 'Authorization': `Bearer ${localStorage.getItem('auth_token')}` + } + }) let data = await response.json() return data @@ -18,7 +26,11 @@ export const fetchSkills = async (link) => { export const fetchItemsForId = async (link, id) => { try { - const response = await fetch(`${link}${id}`) + const response = await fetch(`${link}${id}`, { + headers: { + 'Authorization': `Bearer ${localStorage.getItem('auth_token')}` + } + }) let data = await response.json() return data @@ -30,6 +42,7 @@ export const fetchForm = async (link, info) => { const response = await fetch(link, { method: 'POST', headers: { + 'Authorization': `Bearer ${localStorage.getItem('auth_token')}`, 'Content-Type': 'multipart/form-data' }, body: info @@ -40,14 +53,16 @@ export const fetchForm = async (link, info) => { } export const fetchAuth = async ({ username, password, dispatch }) => { + const baseURL = process.env.REACT_APP_BASE_URL; + const apiURL = process.env.REACT_APP_API_URL; try { const response = await fetch( - 'https://guild.craft-group.xyz/api/user/login', + `${apiURL}/api/user/login`, { method: 'POST', - mode: 'cors', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'Origin': `${baseURL}`, }, body: JSON.stringify({ username,