Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

294
Visualizações
UpdateProfile() during singup Firebase

I'm working on an app and I want to achieve this. When an user signing in I want to get his username and store in firebase. So I created this :

Signup(email: string, password: string, displayName: string) {
    this.angFire.auth.createUser({
      email: email,
      password: password
    }).catch(
      (err) => {
        console.log(err);
        this.error = err;
      })
...

And this works, now I need to save also displayName into current user, so I try to do this inside the same function (Singup()) :

let user = firebase.auth().currentUser;
    user.updateProfile({
      displayName: this.displayName,
      photoURL: "https://example.com/jane-q-user/profile.jpg"
    }).then(function() {
      console.log("Nome utente inserito");
    }, function(error) {
      console.log("Errore durante inserimento utente");
    });

But it gives me this :

error_handler.js:54 EXCEPTION: Error in ./SignupPage class SignupPage - inline template:70:4 caused by: Cannot read property 'updateProfile' of null

How to do it? I'm running on ionic 2 angular2, firebase/angulrfire

Doc ref :

Update a user's profile

You can update a user's basic profile information—the user's display name and profile photo URL—with the updateProfile method. For example:

var user = firebase.auth().currentUser;

user.updateProfile({ displayName: "Jane Q. User", photoURL: "https://example.com/jane-q-user/profile.jpg" }).then(function() {
// Update successful. }, function(error) { // An error happened. });

Here

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

My answer is way too late but just in case someone is interested, you could do it like this

  constructor(
    private afAuth: AngularFireAuth,
    private router: Router
  ) { 
   //
  }


async signupUser(email: string, password: string): Promise<any> {
    const data = await this.afAuth.createUserWithEmailAndPassword(
      email,
      password
    );
    return this.updateUserData(data.user).then(() => {
      this.router.navigate(["/"]);
    });
  }

 private updateUserData({ uid, email, photoURL, displayName }: User) {
    const userRef: AngularFirestoreDocument<User> = this.afs.doc(
      `users/${uid}`
    );
    return userRef.set({ uid, email, photoURL, displayName }, { merge: true });
 }

You can learn more here

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda