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,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-04-09 11:36:01 +02:00
|
|
|
const json = await data.json();
|
|
|
|
|
|
|
|
if (data.status === 403) {
|
|
|
|
return {
|
|
|
|
statusCode: 403,
|
2024-03-10 09:51:15 +01:00
|
|
|
message: json.message,
|
2023-04-09 11:36:01 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return 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
|
|
|
});
|
|
|
|
|
2023-04-09 11:36:01 +02:00
|
|
|
const json = await data.json();
|
|
|
|
|
|
|
|
if (data.status === 403) {
|
|
|
|
return {
|
|
|
|
statusCode: 403,
|
2024-03-10 09:51:15 +01:00
|
|
|
message: json.message,
|
2023-04-09 11:36:01 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return json;
|
2021-06-18 14:57:10 +02:00
|
|
|
};
|
|
|
|
|
2023-03-11 17:58:35 +01:00
|
|
|
export const signOut = async () => {
|
|
|
|
const data = await fetch(`${config.get('api.host')}/authentication/signout`, {
|
|
|
|
method: 'POST',
|
|
|
|
cache: 'no-cache',
|
|
|
|
});
|
|
|
|
|
|
|
|
return data.json();
|
|
|
|
};
|
|
|
|
|
|
|
|
export const verify = async () => {
|
2021-06-18 14:57:10 +02:00
|
|
|
const data = await fetch(`${config.get('api.host')}/authentication/verify`, {
|
|
|
|
method: 'GET',
|
|
|
|
cache: 'no-cache',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
};
|
2024-01-21 18:12:11 +01:00
|
|
|
|
|
|
|
export const refresh = async () => {
|
|
|
|
const data = await fetch(`${config.get('api.host')}/authentication/refresh`, {
|
|
|
|
method: 'GET',
|
|
|
|
cache: 'no-cache',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (data.status === 401) {
|
|
|
|
return {
|
|
|
|
statusCode: 401,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return data.json();
|
|
|
|
};
|