guild_front/src/server/server.js

74 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-07-02 16:02:47 +03:00
export const fetchProfile = async (link, index) => {
2021-07-21 14:40:06 +03:00
try {
2021-08-04 13:04:05 +03:00
const response = await fetch(`${link}${index}`)
let data = await response.json()
2021-06-28 17:57:28 +03:00
2021-08-04 13:04:05 +03:00
return data
2021-07-21 14:40:06 +03:00
} catch (error) {}
2021-08-04 13:04:05 +03:00
}
2021-06-29 17:58:15 +03:00
export const fetchSkills = async (link) => {
2021-07-21 14:40:06 +03:00
try {
2021-08-04 13:04:05 +03:00
const response = await fetch(link)
let data = await response.json()
2021-06-29 17:58:15 +03:00
2021-08-04 13:04:05 +03:00
return data
2021-07-21 14:40:06 +03:00
} catch (error) {}
2021-08-04 13:04:05 +03:00
}
2021-07-03 17:37:30 +03:00
export const fetchItemsForId = async (link, id) => {
2021-07-21 14:40:06 +03:00
try {
2021-08-04 13:04:05 +03:00
const response = await fetch(`${link}${id}`)
let data = await response.json()
2021-07-03 17:37:30 +03:00
2021-08-04 13:04:05 +03:00
return data
2021-07-21 14:40:06 +03:00
} catch (error) {}
2021-08-04 13:04:05 +03:00
}
2021-07-03 17:37:30 +03:00
export const fetchForm = async (link, info) => {
2021-07-21 14:40:06 +03:00
try {
const response = await fetch(link, {
method: 'POST',
headers: {
2021-08-04 13:04:05 +03:00
'Content-Type': 'multipart/form-data'
2021-07-21 14:40:06 +03:00
},
2021-08-04 13:04:05 +03:00
body: info
})
2021-07-03 17:37:30 +03:00
2021-08-04 13:04:05 +03:00
return response
2021-07-21 14:40:06 +03:00
} catch (error) {}
2021-08-04 13:04:05 +03:00
}
export const fetchAuth = async ({ username, password, dispatch }) => {
try {
const response = await fetch(
'https://guild.craft-group.xyz/api/user/login',
{
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
username,
password
})
}
)
if(!response.ok) {
return response.statusText;
}
response
.json()
.then((resJSON) => {
localStorage.setItem('auth_token', resJSON.access_token)
localStorage.setItem('access_token_expired_at', resJSON.access_token_expired_at)
dispatch();
})
} catch (error) {
console.error('Error occured: ', error)
}
}