Merge pull request #4 from apuc/authentication
auth header and env setup
This commit is contained in:
commit
30eec28aec
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
# production
|
# production
|
||||||
/build
|
/build
|
||||||
|
.env
|
||||||
|
|
||||||
# misc
|
# misc
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
11
package-lock.json
generated
11
package-lock.json
generated
@ -5350,9 +5350,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dotenv": {
|
"dotenv": {
|
||||||
"version": "8.2.0",
|
"version": "10.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
|
||||||
"integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw=="
|
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q=="
|
||||||
},
|
},
|
||||||
"dotenv-expand": {
|
"dotenv-expand": {
|
||||||
"version": "5.1.0",
|
"version": "5.1.0",
|
||||||
@ -12872,6 +12872,11 @@
|
|||||||
"workbox-webpack-plugin": "5.1.4"
|
"workbox-webpack-plugin": "5.1.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"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": {
|
"sass-loader": {
|
||||||
"version": "10.2.0",
|
"version": "10.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/sass-loader/-/sass-loader-10.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/sass-loader/-/sass-loader-10.2.0.tgz",
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
"@testing-library/react": "^11.2.7",
|
"@testing-library/react": "^11.2.7",
|
||||||
"@testing-library/user-event": "^12.8.3",
|
"@testing-library/user-event": "^12.8.3",
|
||||||
"bootstrap": "^4.6.0",
|
"bootstrap": "^4.6.0",
|
||||||
|
"dotenv": "^10.0.0",
|
||||||
"eslint": "^7.27.0",
|
"eslint": "^7.27.0",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
"moment": "^2.29.1",
|
"moment": "^2.29.1",
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
export const fetchProfile = async (link, index) => {
|
export const fetchProfile = async (link, index) => {
|
||||||
try {
|
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()
|
let data = await response.json()
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@ -9,7 +13,11 @@ export const fetchProfile = async (link, index) => {
|
|||||||
|
|
||||||
export const fetchSkills = async (link) => {
|
export const fetchSkills = async (link) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(link)
|
const response = await fetch(link, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${localStorage.getItem('auth_token')}`
|
||||||
|
}
|
||||||
|
})
|
||||||
let data = await response.json()
|
let data = await response.json()
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@ -18,7 +26,11 @@ export const fetchSkills = async (link) => {
|
|||||||
|
|
||||||
export const fetchItemsForId = async (link, id) => {
|
export const fetchItemsForId = async (link, id) => {
|
||||||
try {
|
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()
|
let data = await response.json()
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@ -30,6 +42,7 @@ export const fetchForm = async (link, info) => {
|
|||||||
const response = await fetch(link, {
|
const response = await fetch(link, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
'Authorization': `Bearer ${localStorage.getItem('auth_token')}`,
|
||||||
'Content-Type': 'multipart/form-data'
|
'Content-Type': 'multipart/form-data'
|
||||||
},
|
},
|
||||||
body: info
|
body: info
|
||||||
@ -40,14 +53,16 @@ export const fetchForm = async (link, info) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const fetchAuth = async ({ username, password, dispatch }) => {
|
export const fetchAuth = async ({ username, password, dispatch }) => {
|
||||||
|
const baseURL = process.env.REACT_APP_BASE_URL;
|
||||||
|
const apiURL = process.env.REACT_APP_API_URL;
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
'https://guild.craft-group.xyz/api/user/login',
|
`${apiURL}/api/user/login`,
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
mode: 'cors',
|
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json',
|
||||||
|
'Origin': `${baseURL}`,
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
username,
|
username,
|
||||||
|
Loading…
Reference in New Issue
Block a user