Users
const baseURL='https://asia-southeast2-deoapp-indonesia.cloudfunctions.net'
const options={
headers : {
'Content-Type': 'application/json',
'Authorization': process.env.REACT_APP_FUNCTIONS_KEY
}}
const data = { email: email, name: name, companyId: globalState.currentCompanies.id }
export const createUserFunctions =async(data)=>{
const newUrl = `${baseURL}/createUser`
return axios.post(newUrl,data,options)
.then((x)=> x.data)
.catch((err)=>console.log(err))
}
const handleAddNewUser = () => {
setLoading(true)
const conditions = [
{ field: "email", operator: "==", value: email.toLowerCase() },
];
getCollectionFirebase('users',conditions)
.then((x)=>{
if(x){
console.log(x)
arrayUnionFirebase('companies',globalState.currentCompanies.id,'users',[x[0].id])
.then()
.catch((err)=>console.log(err.message))
}
else{
createUserFunctions({ email: email, name: name, companyId: globalState.currentCompanies.id })
.then()
.catch((err)=> console.log(err.message))
}
setLoading(false)
onClose()
})
.catch((err)=>console.log(err.message))
//create new user
}Last updated