Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Firebase updateProfile does not exist on type 'User'

For a final school project. I have to create some sort of to-do application with firebase as a database and authentification tool.
I allow some kind of username change so people can get creative.
On the homescreen, there is a dashboard with a welcome sign. Until the user doesn’t have a username, the current UID is shown. You can change this with a form.
The point is that when I want to write the code to update the users username, I get an error with the message:

Property ‘updateProfile’ does not exist on type ‘User’.

I find this rather strange because I’m implementing the code the way as it is documented on the original firebase documentation. Is there anyone who can see if there is an error or a clue to get the problem fixed?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Now I’ve putted the code into an onAuthStateChanged-codeblock so I can get the users actual credentials instead of null.. . ideally, the code is seperated in another block

const userCred = () => {
  onAuthStateChanged(auth, (user) => {
    if (user) {
      const { uid } = user;
      const userPlaceholder = document.querySelector<HTMLHeadElement>('#dashboardName');
      const displaynamePlaceholder = document.querySelector<HTMLInputElement>('#displaynameInput');
      console.log(userPlaceholder);
      if (user.displayName !== null) {
        userPlaceholder!.innerHTML = `Welcome ${user.displayName}`;
        displaynamePlaceholder!.setAttribute('value', `${user.displayName}`);
      } else {
        userPlaceholder!.innerHTML = `Welcome ${uid}`;
        displaynamePlaceholder!.setAttribute('value', `${uid}`);
        userPlaceholder!.style.fontSize = '1.6rem';
      }
    }
    const displaynamePlaceholder = document.querySelector<HTMLInputElement>('#displaynameInput')?.value;
    user?.updateProfile({
      displayName: String(displaynamePlaceholder),
      photoURL: null,
    });
  });
  console.log('not logged in');
};

here is my code:

>Solution :

That is probably due to you were looking at Firebase v8 documentation while using the Firebase v9 in your app. As per firebase v9 User documentation there is no updateProfile method in User anymore. It is a standalone function now, here are the docs.

import { getAuth, updateProfile } from "firebase/auth";
const auth = getAuth();
updateProfile(auth.currentUser, {
  displayName: "Jane Q. User", photoURL: "https://example.com/jane-q-user/profile.jpg"
}).then(() => {
  // Profile updated!
  // ...
}).catch((error) => {
  // An error occurred
  // ...
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading