capacitor-firebase-auth icon indicating copy to clipboard operation
capacitor-firebase-auth copied to clipboard

Add Error Codes to handleError

Open qnlbnsl opened this issue 4 years ago • 1 comments

Currently, the errors thrown by the plugin are just messages. Is there any plan to support specific codes as referenced in the firebase auth library. We would like to use those error codes to perform additional things like account linking.

Example: If I'm signed up with google and use the same email on apple/facebook, then the firebase sdk would throw an error iOS: FIRAuthErrorCodeEmailAlreadyInUse Web: auth/account-exists-with-different-credential

Within our webview, we could then just reference the SDKs and perform additional steps like linking with credentials.

qnlbnsl avatar Sep 29 '20 13:09 qnlbnsl

@qnlbnsl this feature isn't already implemented?

import { cfaSignIn } from 'capacitor-firebase-auth';
import firebase from 'firebase/app';

/**
 * Sign in with Google account using Capacitor Firebase Auth
 */
signInWithGoogle() {
  cfaSignIn('google.com').subscribe( // or cfaSignInGoogle().subscribe(
    (user: firebase.User) => this.onSignInWithCfa(user),
    (error) => this.onCfaError(error)
  );
}

private onSignInWithCfa(firebaseUser: firebase.User) {
  // do stuff
}

private onCfaError(error: any) {
  if (error.code === 'auth/account-exists-with-different-credential') {
    // show message
  } else {
    // show another message
  }
}

joseph-navant avatar Mar 03 '21 01:03 joseph-navant