1
0
Fork 0
mirror of synced 2024-10-03 02:27:06 +13:00
budibase/packages/client/src/api/auth.js

31 lines
688 B
JavaScript

import API from "./api"
import { enrichRows } from "./rows"
import { TableNames } from "../constants"
/**
* Performs a log in request.
*/
export const logIn = async ({ email, password }) => {
if (!email) {
return API.error("Please enter your email")
}
if (!password) {
return API.error("Please enter your password")
}
return await API.post({
url: "/api/authenticate",
body: { email, password },
})
}
/**
* Fetches the currently logged in user object
*/
export const fetchSelf = async () => {
const user = await API.get({ url: "/api/self" })
if (user?._id) {
return (await enrichRows([user], TableNames.USERS))[0]
} else {
return null
}
}