2017-11-04 14:22:31 +01:00
|
|
|
import { throwIfNotSuccess, headers } from './helper';
|
|
|
|
|
|
|
|
const URI = 'api/admin/user';
|
|
|
|
|
2018-04-16 11:23:22 +02:00
|
|
|
function logoutUser() {
|
|
|
|
return fetch(`${URI}/logout`, { method: 'GET', credentials: 'include' })
|
|
|
|
.then(throwIfNotSuccess)
|
|
|
|
.then(response => response.json());
|
|
|
|
}
|
|
|
|
|
2017-11-04 14:22:31 +01:00
|
|
|
function fetchUser() {
|
|
|
|
return fetch(URI, { credentials: 'include' })
|
|
|
|
.then(throwIfNotSuccess)
|
|
|
|
.then(response => response.json());
|
|
|
|
}
|
|
|
|
|
|
|
|
function unsecureLogin(path, user) {
|
|
|
|
return fetch(path, { method: 'POST', credentials: 'include', headers, body: JSON.stringify(user) })
|
|
|
|
.then(throwIfNotSuccess)
|
|
|
|
.then(response => response.json());
|
|
|
|
}
|
|
|
|
|
2020-05-12 22:57:33 +02:00
|
|
|
function passwordLogin(path, data) {
|
|
|
|
return fetch(path, {
|
|
|
|
method: 'POST',
|
|
|
|
credentials: 'include',
|
|
|
|
headers,
|
|
|
|
body: JSON.stringify(data),
|
|
|
|
}).then(throwIfNotSuccess);
|
|
|
|
}
|
|
|
|
|
2017-11-04 14:22:31 +01:00
|
|
|
export default {
|
|
|
|
fetchUser,
|
|
|
|
unsecureLogin,
|
2018-04-16 11:23:22 +02:00
|
|
|
logoutUser,
|
2020-05-12 22:57:33 +02:00
|
|
|
passwordLogin,
|
2017-11-04 14:22:31 +01:00
|
|
|
};
|