Promise data is undefined in second .then()

Hi all,
So I’ve been trying to get stuff to work with promises, because from what I can tell its a good way of doing stuff and not causing hang time in apps, but I’ve run into an issue. I have a promise which works fine and deals with firebase login. Then within the then for that promise I have an observable which gets the users id, which then returns a promise which checks if the user has a profile then will redirect to either the page to create a profile or to the homepage. Here is my code

Login.ts

async login(user: User){
  	await this.fb.login(user)
    .then(() => {
      this.auth.authState.take(1).subscribe(data => {
        if(data && data.email && data.uid){
          return this.request.get('api/has_profile/' + data.uid, {});
        }
      });
    })
    .then(function(response){
      console.log(response);
    });
  }

I have tested the this.request.get('api/has_profile/' + data.uid, {}); promise before from another function and it worked fine and was returning everything I was expecting, however it seems like when I return it from within another promise all I get back in the response variable is ‘undefined’. Can anyone help here? I feel like I’m overlooking something obvious…
Thanks in advance for any help!

1 Like