Angularfire2 and Rxjs Observable Not firing Catch and Complete Methods

Hllink

i did an auth on my site, it works fine, but i want to handle errors, for testing i caused one for this purpose with this return from firebase: "An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address.". Im trying to write an RXjs observable to do that, with the following code:

private subscribleAuth() {
    this.af.auth
        .subscribe(
            auth => {
                this._auth = auth && auth.auth ? auth.auth : null;
                if (this._auth) {
                    this.loginState = 'logged';
                } else {
                    this.loginState = 'login';
                }

            },
            err => {
                console.log('error'),
                    this.loginState = 'error';
            },
            () => { console.log('done.') }
        );
}

My console never show the 'error' or 'done', so anything i put inside the err code doesn't work.

enter image description here

note: I know what causes that firebase return, i just want to know how treat it and why the code i wrote isn't worked as expected, when no errors are returned the site works as expected with the same observable.

I'm using angularfire2: ^2.0.0-beta.5 with Angular 2.0.0 final

EDIT 1: even the official github project tells you to get the user as an observable and subscrible to it on Override configuration / No config Example app section..

EDIT 2: reported as an issue and maybe it's really a bug, gonna keep this post updated. The workarround by now is using this code written by yashmurty on github:

import { AngularFire, AuthProviders } from 'angularfire2';
import { AuthBackend } from 'angularfire2/auth/auth_backend';

export class SocialmenuComponent {
    constructor(public af: AngularFire, private _authBackend: AuthBackend) {
        // this.af.auth.subscribe(
        this._authBackend.getRedirectResult().subscribe(
            (auth) => {
                if(auth) {
                  console.log(auth);
                } else {
                  console.log('User Not Logged In');
                }
            },
            (err) => {
                if(err) {
                  console.log('Error in auth.subscribe : ');
                  console.log(err);
                } else {
                  console.log('No Error detected in auth.subscribe');
                }
            },
            () => { console.log('done.') }
        );
    }
}
cartant

Any errors that occur when calling the createUser or login methods of the AngularFire2 auth observable are reported via the returned promises, not via the observable.

For example:

import { AngularFire } from 'angularfire2';

...
class MyComponent {

  constructor(af: AngularFire) {

    af.auth.createUser({
      email: '[email protected]',
      password: 'somepassword'
    })
    .then((authState) => { console.log('success'); })
    .catch((error) => { console.log('failure'); });
  }

If authenticating using a method that involves a redirect, you can do something like this (jeffbcross solution from github):

import { FirebaseApp } from 'angularfire2';
import * as firebase from 'firebase';

...
class MyComponent {

  constructor(@Inject(FirebaseApp) fbApp: firebase.App) {

    fbApp.auth().getRedirectResult()
    .then((userCredential) => { console.log('success'); })
    .catch((error) => { console.log('failure'); });
  }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

RxJS catch **and** retry an Observable

Catch Complete Within RxJS Pipe

RxJs Observable not calling complete method

Angularfire2 Observable Recursion

RxJS (Interval) Observable wait for last observable to complete

RxJS: why is inner observable firing first?

RXJS zip of zip (arrays) observable is not firing

RxJS wait for an observable to complete in its entirety

How can I complete Observable in RxJS

RxJS - subscribe only once but do not complete Observable

Angular 6 and AngularFire2 RxJS Error

Catch errors from FirebaseListObservable on Angularfire2

AngularFire2 promises into Observable type Issues

'body' property missing on rxjs observable catch error

Observable.catch() and exception handling in RxJs

Multiple auth methods using AngularFire2

Difference between the methods .pipe() and .subscribe() on a RXJS observable

Can I catch certain errors before "subscribe()" in an RXJS observable in Angular2?

Angular2 Http with RXJS Observable TypeError: this.http.get(...).map(...).catch is not a function

value from Observable within Observable using angularfire2 firestore

Creating an auto complete search using angularfire2 and firestore?

RxJS - observable doesn't complete when an error occurs

Testing RxJS observable that tracks the last emitted value (no complete signal)?

RxJs: How to only maintain the latest value until inner observable complete

Does RxJs .first() operator (among others) complete the source observable?

How to solve rxjs Typescript error (Ionic 3, angularfire2)

Is this the correct way to use rxjs MergeMap in angularfire2?

Catch in Angularfire2 v5 error

angular2 rxjs shared subscribe not firing

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  3. 3

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    Do Idle Snowflake Connections Use Cloud Services Credits?

  9. 9

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  10. 10

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  11. 11

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  12. 12

    Generate random UUIDv4 with Elm

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  17. 17

    EXCEL: Find sum of values in one column with criteria from other column

  18. 18

    Pandas - check if dataframe has negative value in any column

  19. 19

    How to use merge windows unallocated space into Ubuntu using GParted?

  20. 20

    Make a B+ Tree concurrent thread safe

  21. 21

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

HotTag

Archive