Hemmelig.app/client/api/authentication.js

97 lines
2.1 KiB
JavaScript
Raw Normal View History

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,
};
}
const json = await data.json();
if (data.status === 403) {
return {
statusCode: 403,
message: json.message,
};
}
return json;
};
2021-06-27 21:03:47 +02:00
export const signUp = async (email, username, password) => {
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 }),
});
const json = await data.json();
if (data.status === 403) {
return {
statusCode: 403,
message: json.message,
};
}
return json;
};
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 () => {
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();
};
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();
};