Error: The method this._parentSubscription.unsubscribe() does not exist

When encountering an error, a TypeError is being caused within the observable. Despite removing fbLogin.unsubscribe();, the error persists and I am unsure of the root cause. My project utilizes rxjs@^5.5.2.

ERROR TypeError: this._parentSubscription.unsubscribe is not a function
    at Subscriber._unsubscribeParentSubscription (Subscriber.js:110)
    at Subscriber.error (Subscriber.js:75)
    at auth.ts:54
    at e.b (auth.esm.js:17)
    at Fb (auth.esm.js:20)
    at Bb (auth.esm.js:20)
    at A.g.Xb (auth.esm.js:19)
    at kb (auth.esm.js:13)
    at t.invoke (polyfills.js:3)
    at Object.onInvoke (core.js:4760)


//login.ts
loginWithFacebook(): void{
        let fbLogin = this.authData.loginWithFacebook().subscribe(() => {
            fbLogin.unsubscribe();
            this.navCtrl.setRoot('HomePage');
        }, error => {
           fbLogin.unsubscribe();
            console.log(error);
        });
    }


//auth.ts
loginWithFacebook(): Observable<any> {
        return Observable.create(observer => {
            if (this.platform.is('cordova')) {
                return this.fb.login(['email', 'public_profile']).then(res => {
                    const facebookCredential = firebase.auth.FacebookAuthProvider.credential(res.authResponse.accessToken);
                    this.afAuth.auth.signInWithCredential(facebookCredential).then(()=> {
                        observer.next();
                    }).catch(error => {
                        console.log(error);
                        observer.error(error);
                    });
                });
            } else {
                return this.afAuth.auth.signInWithPopup(new firebase.auth.FacebookAuthProvider()).then(()=> {
                    observer.next();
                }).catch(error => {
                    console.log(error);
                    observer.error(error); //this is auth.ts:54
                });
            }
        });
    }

Answer №1

Unfortunately, at this time, async functions are not compatible with the Observable.create method according to a comment in an RxJs issue (source).

To work around this limitation, you can use either from or defer to convert your Promise into an Observable.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Obtain the data from onTouchTap action

Currently, I have a class that is returning an event to the parent. My goal is to extract the number of the touched button (the label on RaisedButton). Although I am successfully returning the event, I am unable to locate the desired information when I l ...

Failed to convert video to blob and upload it due to readAsArrayBuffer returning an empty array

Currently, I am facing an issue while attempting to upload a video using Ionic, Capacitor, and React. To achieve this, I have integrated the cordova-video-capture-plus plugin into my project. The problem arises when I try to execute the readAsArrayBuffer ...

Creating an Escape key press event in plain Typescript without using JQuery

Is there a way to trigger an Escape button press event in Angular unit tests? const event = document.createEvent('UIEvent'); event.initUIEvent('keydown', true, true, window, 0); (<any>event).keyCode = 27; (<any ...

While attempting to update the package.json file, I encountered an error related to the polyfills in Angular

I have been working on a project with ng2 and webpack, everything was running smoothly until I updated the package.json file. Since then, I have been encountering some errors. Can anyone please assist me in identifying the issue? Thank you for any help! P ...

Enhancing Material UI v4 Themes using TypeScript

I am attempting to implement my own custom palette option in the theme section, but I am struggling with how to do the augmentation part using TypeScript. So far, I have created a file named "material-ui.d.ts" and inside it, I only have: import { PaletteO ...

utilizing regular expressions to retrieve data

I am facing a challenge in extracting both the product name and price from the given data. The desired result, which includes both the product name and price, is not on the same line. How can I include the line that comes before the price as well? Here is ...

The process of extracting all arrays from a JSON object

Within my JSON object, there is a list of countries each with multiple regions stored in an array. My goal is to extract and combine all the regions into one single list. However, when I attempt to map the data, it does not consolidate all the regions as e ...

Unable to call a component's method from a different component in Angular 7

How can I call the toggleSidebar() method of the SidebarComponent from the HeaderComponent using the callToggleSidebarOnToggleSidebarBtn() method? I am encountering an error that I cannot comprehend. What is the correct way to use a method of one component ...

Guide to inheriting functions from a parent component in Angular 2

Hello, I am a beginner in the realm of angular2 and would appreciate any assistance in refining my vocabulary and terminology. Currently, I have a class that consists of two directives structured as follows: In parent.component.ts, the Parent component i ...

Decide on the return type of a generic function depending on the parameters of the function

I have a series of TypeScript functions that are structured as follows: useCustomFunction = <T>(key: CustomType) : T => { // implementation details here } The parameter type is restricted to a specific set of strings: type CustomType = "apple ...

Guide on simulating rxjs/Websocket in angular for performing Unit Testing

I have developed a service that manages websocket communication with a server and I am looking to create unit tests for it. However, I am facing challenges in mocking rxjs/Websocket. While searching for a solution, I came across a similar question here, b ...

Removing the final element within a nested array: a step-by-step guide

let originalArray=[ [ "Test1", "4", "160496" ], [ "Test2", "6", "38355" ], [ "Test3", "1", "1221781" ], [ " ...

Determining the data type of an object property using a variable

I just joined a pre-existing project, where there are some global variables set by the backend. These globals are defined in an interface: interface IGlobals { feature_foo: boolean feature_bar: boolean someOtherProp: string } const globals: IG ...

incorrect implementation of react lifecycle phases

My Sharepoint Framework webpart includes a property side bar where I can choose a Sharepoint List, and it will display the list items from that list in an Office UI DetailsList Component. Although all REST calls are functioning properly during debugging, ...

The 'subscribe' property is not found in the type 'OperatorFunction<Response, Recipe[]>'

I'm encountering an issue while attempting to retrieve data from firebase "Property 'subscribe' does not exist on type 'OperatorFunction'" Any suggestions on what might be missing here? import { Injectable } from '@angula ...

Having trouble with importing rxjs operators

After updating the imports for rxjs operators in my project to follow the new recommended syntax, I encountered an issue with the "do" operator. While switchMap and debounceTime were updated successfully like this: import { switchMap, debounceTime } ...

Minimize overlap across both projects

One scenario is having two projects that utilize a lot of the same components. How can we minimize redundancy between them? Is there a way to make them shareable? Perhaps leveraging webpack could be the solution? ...

Encountering a Problem with vue-check-view Library in Typescript

After successfully declaring the js plugin with *.d.ts, I encountered an issue where my view was blank after using .use(checkView). Does the library vue-check-view support Typescript? Error: Uncaught TypeError: Cannot read property '$isServer' o ...

React onClick event image attribute is unique because it allows for interactive

Is there a way to dynamically add the onClick attribute to an image, but have the click event not working? //Code const parser = new DOMParser(); const doc = parser.parseFromString(htmlContent, "text/html" ); const imageDa ...

Encountering the error message "Type '{ theme: Theme; }' is not compatible with type" while attempting to pass it as a prop to the App component

Trying out a new strategy for my app initialization by incorporating the use of the useLocation hook within my App component. I'm still learning Typescript and encountering a problem. This is what I have so far: // index.tsx const theme: Theme = cre ...