Skip to content

Create User

Danny Hinshaw edited this page Dec 11, 2018 · 8 revisions

Create User

To create a user you first need an organization to attach them to. Once you have an organization ID you can use your firebase user tokenID to send an authenticated request to the /createUser endpoint.

Example

// Authenticate as admin
const authRef = firebase.auth();
const userCred: UserCredential = await authRef.signInWithEmailAndPassword("your-email@example.com", "your-password");
const tokenID: string = await userCred.user.getIdToken();


// Example user data
const userData = {
  email: 'user1@example.com',
  password: '<USER_PASSWORD>',
  organizationID: '<YOUR_ORG_ID>'
};


// Example request data
const requestObj = {
  method: 'post',
  body: JSON.stringify(userData),
  headers: {
    'Authorization': `Bearer ${tokenID}`,
    'Content-Type': 'application/json'
  }
};


// URL For triggering http cloud functions
const apiBaseURL = "https://us-central1-mrg-production-8813d.cloudfunctions.net";


// Call the https endpoint
fetch(apiBaseURL.concat('/createUser'),tokenID)
  .then((res) => res.json())
  .then((json) => console.log(json)); 
  // response ex. { userId: "HD324kjsfUSl34" }

Clone this wiki locally