Generateurv2/frontend/requests/requests.users.js

84 lines
1.8 KiB
JavaScript
Raw Normal View History

2022-06-11 23:39:03 +02:00
import { usersInstance } from "../apis/users.instance.js";
export const registerNewUser = async (data) => {
return await usersInstance
.request({
method: "POST",
url: "register/",
data: { ...data },
2022-06-24 13:42:16 +02:00
headers: {
Authorization: null,
},
2022-06-11 23:39:03 +02:00
})
.then((res) => res.data);
};
export const loginRequest = async (data) => {
return await usersInstance
.request({
method: "POST",
url: "login/",
data: { ...data },
headers: {Authorization: null}
})
.then((res) => res.data);
};
2022-06-24 13:42:16 +02:00
export const getUser = async () => {
2022-06-11 23:39:03 +02:00
return await usersInstance
.request({
method: "GET",
2022-06-24 13:42:16 +02:00
url: "api_user/",
headers: {
Authorization:
localStorage.getItem("token") !== null
? `Token ${localStorage.getItem("token")}`
: null,
},
2022-06-11 23:39:03 +02:00
})
.then((res) => res.data);
};
2022-06-24 13:42:16 +02:00
export const changeUser = async ( data) => {
return await usersInstance
.request({
method: "PUT",
url: "api_user/",
data: { ...data },
headers: {
Authorization:
localStorage.getItem("token") !== null
? `Token ${localStorage.getItem("token")}`
: null,
},
})
.then((res) => res.data)
.catch((err) => {
throw err;
});
};
export const changePassword = async ( data) => {
return await usersInstance
.request({
method: "POST",
url: "password/change/",
data: { ...data },
headers: {
Authorization:
localStorage.getItem("token") !== null
? `Token ${localStorage.getItem("token")}`
: null,
},
})
};
2022-06-11 23:39:03 +02:00
export const logoutRequest = async (token) => {
return await usersInstance
.request({
method: "POST",
url: "logout/",
headers: {Authorization: `Token ${token}`}
})
.then((res) => res.data);
};