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

141
Visualizações
Resolving Promise on Page Load using route resolver

I'm using AngularFireAuth module to get the current user's UID to the component on page load through route resolving, but the lines of code needed to return the unwrapped promise to the component don't seem to be resolving and leave the promise unfulfilled.

relevant Routing Module Code for the edit-profiles module:

const routes: Routes = [
  {
    path: '',
    component: EditProfilesComponent,
    resolve: { userUID: UserInfoService },
  },
];

The resolver service code is as follows:

export class UserInfoService implements Resolve<any> {
  constructor(public afAuth: AngularFireAuth, public af: AngularFirestore) {}

  async resolve() {
    const user = await this.afAuth.currentUser;
    const userUID = user?.uid;
    return userUID; //returns undefined 
  }
}

I've also tried making it one promise and resolving it but that returned undefined as well. The code looked like this:

const promise = new Promise(async(resolve, reject) => {
const user = await this.afAuth.currentUser
const userUID = user?.uid;
resolve(userUID) 

})

And then the EditProfiles consumer component code is:

export class UserInfoService implements Resolve<any> {
  constructor(public afAuth: AngularFireAuth, public af: AngularFirestore) {}

  async resolve() {
    const user = await this.afAuth.currentUser;
    const userUID = user?.uid;
    return userUID; //returns undefined 
  }
}

I'm really not sure how to make it so that the promise returns the userUID to be used and consumed by that component, and display user-specific data, but I'm not sure how to make sure it's there before the component is instantiated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

@Bravo was right it was a problem with the design of the code it turns out what I actually wanted was for the page to wait until the promise was resolved to print out the data so what was needed on the ngOnInit was the following code

ngOnInit(): void {
    this.afAuth.authState.subscribe((user) => {
        if(user) {
            //write logic here to make sure the promise gets resolved
        } else {
            //logic for when the page is getting the information
        }
    })
}

This is how you make sure that promises sent from firebase are resolved, you subscribe to the authstate observable and when that observable returns true, then you can finally retrieve the information from firebase that you need, that's the key piece that I was missing that it turns out that route resolvers may not have been the best tool for.

about 4 years ago · Juan Pablo Isaza 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