baumblatt / capacitor-firebase-auth

Capacitor Firebase Authentication Plugin
MIT License
261 stars 129 forks source link

Add Error Codes to handleError #117

Closed qnlbnsl closed 1 year ago

qnlbnsl commented 4 years ago

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.

joseph-navant commented 3 years ago

@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
  }
}