1
0
Fork 0
mirror of synced 2024-09-17 09:49:11 +12:00
budibase/packages/client/src/api/authenticate.js
2020-02-03 09:24:25 +00:00

22 lines
539 B
JavaScript

export const USER_STATE_PATH = "_bbuser"
export const authenticate = api => async ({ username, password }) => {
if (!username) {
api.error("Authenticate: username not set")
return
}
if (!password) {
api.error("Authenticate: password not set")
return
}
const user = await api.post({
url: "/api/authenticate",
body: { username, password },
})
// set user even if error - so it is defined at least
api.setState(USER_STATE_PATH, user)
localStorage.setItem("budibase:user", JSON.stringify(user))
}