Skip to content

Update User

Danny Hinshaw edited this page Dec 20, 2018 · 1 revision

Create User

To update a user send an authenticated request to the /updateUser endpoint.

Example

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


// Example userupdate data
const userUpdateData = {
  id: "12345",                     // required - Id of user to update.
  emailVerified: true,             // optional
  displayName: "NEW_DISPLAY_NAME", // optional
  phoneNumber: "NEW_PHONE",        // optional
  disabled: false,                 // optional
  photoURL: "NEW_URL",             // optional
  password: "NEW_PASSWORD",        // optional
  email: "NEW_EMAIL"               // optional
};


// Example request data
const requestObj = {
  method: 'post',
  body: JSON.stringify(userUpdateData),
  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('/updateUser'),tokenID)
  .then((res) => res.json())
  .then((json) => console.log(json)); 
  // response is full user data JSON