Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70434

Firebase signInWithRedirect stop service?

$
0
0

Hello guys I’m trying to make a login with firebase using signInWithRedirect but after redirect all the data is lost and I can’t get the error from the try catch in the async call. Is there any way to persist this data or class even if it redirects me to other page ?

Whenever the redirect happens and I get back to my page my service constructor is called again.

  async platformSignMethod(provider: auth.AuthProvider): Promise<any> {
    if (this.platform.is('desktop')) {
      return this.angularFireAuth.signInWithPopup(provider);
    } else {
      // web but not desktop, for example mobile PWA
      return this.angularFireAuth.signInWithRedirect(provider);
    }
  }
  async socialSignIn(providerName: string, scopes?: Array<string>): Promise<any> {
    const provider = new auth.OAuthProvider(providerName);

    // add any permission scope you need
    if (scopes) {
      scopes.forEach(scope => {
        provider.addScope(scope);
      });
    }

    try {
     await this.platformSignMethod(provider);

    } catch (error) {

      if (error.code === 'auth/account-exists-with-different-credential') {
        var pendingCred = error.credential;
        var email = error.email;

        const providers = await this.angularFireAuth.fetchSignInMethodsForEmail(email);
        if (providers[0] === 'password') {
          this.promptUserForPasswordSubject.next(true);
          return;
        }

        const firstProviderMethod = providers.find(p => this.supportedSignInMethods.includes(p));
        if (!firstProviderMethod) {
          throw new Error(`Your account is linked to a provider that isn't supported.`);
        }
  
        const linkedProvider = this.getProvider(firstProviderMethod) as auth.OAuthProvider;
        linkedProvider.setCustomParameters({ login_hint: email });

        await this.platformSignMethod(linkedProvider);
        const user = await this.getUser();
        await user.linkWithCredential(pendingCred);
      }
    }
  }

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 70434

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>