Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: afAuth.idToken returns firebase.User instead of idToken #1069

Closed
craiggoldstone opened this issue Jul 13, 2017 · 5 comments
Closed

Bug: afAuth.idToken returns firebase.User instead of idToken #1069

craiggoldstone opened this issue Jul 13, 2017 · 5 comments

Comments

@craiggoldstone
Copy link

Version info

Angular: 4.1.3
Firebase: 4.1.3
AngularFire: 4.0.0-rc.1

afAuth.idToken and afAuth.authState seem to be duplicates of each other, both having the type Observable<firebase.User> and identical implementations. I understand this may be fallout from v4.0.0 but I can't see any reason why .idToken shouldn't return the actual token.

My workaround is as follows:

// idToken: Observable<string>;
// note: can't use Observable.fromPromise because firebase.Promise can't be cast to Promise
this.idToken = this.afAuth.idToken.mergeMap((user) => {
  return Observable.from(user.getIdToken());
});

I am quite happy to submit a PR to alter .idToken to be Observable<string>. Please let me know of I should go ahead.

@jamesdaniels
Copy link
Member

Behaving as expected, though the naming is odd, it reflects the JS SDK.

As of 4.0 onAuthStateChanged is now only triggered on sign-in and out,
onTokenIdChanged is the pre-4.0 behavior it's a firebase.User callback which is triggered on all token changes.

@jamesdaniels
Copy link
Member

@davideast what do you think?

@jamesdaniels jamesdaniels reopened this Jul 14, 2017
@jamesdaniels
Copy link
Member

Yeah, on second thought I think I agree

@larssn
Copy link
Contributor

larssn commented Aug 14, 2017

Well my 2c is that the JS SDK is pretty weird/unintuitive in that aspect; might not wanna model that weirdness in AF2.

@larssn
Copy link
Contributor

larssn commented Aug 14, 2017

Btw @craigsnyders , this is a shorter equivalent version of your code:

this.idToken = this.afAuth.idToken.map(user => user.getIdToken());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants