2022-01-20 10:40:53 +01:00
|
|
|
export const buildAuthEndpoints = API => ({
|
|
|
|
/**
|
|
|
|
* Performs a log in request.
|
|
|
|
*/
|
|
|
|
logIn: async ({ email, password }) => {
|
|
|
|
if (!email) {
|
|
|
|
return API.error("Please enter your email")
|
2021-07-07 12:28:35 +02:00
|
|
|
}
|
2022-01-20 10:40:53 +01:00
|
|
|
if (!password) {
|
|
|
|
return API.error("Please enter your password")
|
|
|
|
}
|
|
|
|
return await API.post({
|
|
|
|
url: "/api/global/auth",
|
|
|
|
body: {
|
|
|
|
username: email,
|
|
|
|
password,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2022-01-20 10:43:23 +01:00
|
|
|
/**
|
|
|
|
* Logs the user out and invalidates their session.
|
|
|
|
*/
|
|
|
|
logOut: async () => {
|
|
|
|
return await API.post({
|
|
|
|
url: "/api/global/auth/logout",
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2022-01-20 10:40:53 +01:00
|
|
|
/**
|
|
|
|
* Fetches the currently logged in user object
|
|
|
|
*/
|
|
|
|
fetchSelf: async () => {
|
|
|
|
return await API.get({ url: "/api/self" })
|
|
|
|
},
|
|
|
|
})
|