2021-06-18 14:57:10 +02:00
|
|
|
import config from '../config';
|
|
|
|
|
|
|
|
export const signIn = async (username, password) => {
|
|
|
|
const data = await fetch(`${config.get('api.host')}/authentication/signin`, {
|
|
|
|
method: 'POST',
|
|
|
|
cache: 'no-cache',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
body: JSON.stringify({ username, password }),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (data.status === 401) {
|
|
|
|
return {
|
|
|
|
statusCode: 401,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-09-13 20:48:13 +02:00
|
|
|
return data.json();
|
2021-06-18 14:57:10 +02:00
|
|
|
};
|
|
|
|
|
2021-06-27 21:03:47 +02:00
|
|
|
export const signUp = async (email, username, password) => {
|
2021-06-18 14:57:10 +02:00
|
|
|
const data = await fetch(`${config.get('api.host')}/authentication/signup`, {
|
|
|
|
method: 'POST',
|
|
|
|
cache: 'no-cache',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
2021-06-27 21:03:47 +02:00
|
|
|
body: JSON.stringify({ email, username, password }),
|
2021-06-18 14:57:10 +02:00
|
|
|
});
|
|
|
|
|
2022-09-13 20:48:13 +02:00
|
|
|
return data.json();
|
2021-06-18 14:57:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export const verify = async (token) => {
|
|
|
|
const data = await fetch(`${config.get('api.host')}/authentication/verify`, {
|
|
|
|
method: 'GET',
|
|
|
|
cache: 'no-cache',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
Authorization: `Bearer ${token}`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (data.status === 401) {
|
|
|
|
return {
|
|
|
|
statusCode: 401,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-09-13 20:48:13 +02:00
|
|
|
return data.json();
|
2021-06-18 14:57:10 +02:00
|
|
|
};
|