Skip to main content

add-user

Adding a user

  • localhost:3000/adduser

Users are added with Supabase using the client import { supabase } from "@utils/supabaseClient";

As with the import user function the auth user needs to be created using a serverless function:

src/pages/adduser.js
async function addUser() {
const newDOB = year.entry + "-" + month.entry + "-" + day.entry;

const userDataToSend = {
name: Name.entry,
gender: gender,
role: role,
province: province,
district: district,
health_facility: healthFacility,
country: country,
organisation: organisation,
mobile_number: mobileNumber.entry,
DOB: newDOB,
};

try {
setLoading(true);
const { data, error } = await supabase.functions.invoke("add-user", {
body: JSON.stringify(mobileNumber),
});

if (error) alert(error);

if (data) {
if (data.error) {
console.log(data.error);
setErrorOnSubmit(data.error);
} else {
setResponseJson(data);
addUserProfile(data, userDataToSend);
setErrorOnSubmit(false);
setUserCreated(true);
}
}
} catch (error) {
console.log(error);
} finally {
setLoading(false);
}
}