Generateurv2/frontend/requests/requests.users.js
2022-06-24 13:42:16 +02:00

84 lines
1.8 KiB
JavaScript

import { usersInstance } from "../apis/users.instance.js";
export const registerNewUser = async (data) => {
return await usersInstance
.request({
method: "POST",
url: "register/",
data: { ...data },
headers: {
Authorization: null,
},
})
.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);
};
export const getUser = async () => {
return await usersInstance
.request({
method: "GET",
url: "api_user/",
headers: {
Authorization:
localStorage.getItem("token") !== null
? `Token ${localStorage.getItem("token")}`
: null,
},
})
.then((res) => res.data);
};
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,
},
})
};
export const logoutRequest = async (token) => {
return await usersInstance
.request({
method: "POST",
url: "logout/",
headers: {Authorization: `Token ${token}`}
})
.then((res) => res.data);
};