Skip to content

Incoherent data structure on AuthError #5599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks
PabloLION opened this issue Oct 10, 2021 · 3 comments
Closed
2 tasks

Incoherent data structure on AuthError #5599

PabloLION opened this issue Oct 10, 2021 · 3 comments

Comments

@PabloLION
Copy link
Contributor

PabloLION commented Oct 10, 2021

[REQUIRED] Describe your environment

  • Operating System version: Windows 20H2 (Windows 10 10.0.19042)
  • Browser version: Chrome 92 (Chrome: 92.0.4515.159)
  • Firebase SDK version: 9.1.2 ("firebase": "^9.1.2")
  • Firebase Product: auth

[REQUIRED] Describe the problem

Data structure different in production environment than in official doc and source code.

  • Also this part seems to be outdated(v8 SDK yet shown up in a v9 page)
    like auth.signInWithPopup(OAuthprovider) should be signInWithPopup(authInstance,OAuthProvider), so should auth.signInWithEmailAndPassword(email, password) (first arg: auth instance)... etc.
  • Please confirm if I did everything right: I filled in two forms with screenshot and details but the feedback system seems not to be user-friendly. I cannot get and feedback(of update) of my feedback. The two feedback forms are about last <li> and the official doc page

Steps to reproduce:

  1. Create an account in GitHub with a email userEmail.
  2. Create an account in Firebase Auth with same email userEmail.
  3. Setup Firebase OAuth with GitHub
  4. Login with OAuth. Then you'll get an Error authErr with error code AuthErrorCodes.NEED_CONFIRMATION === "auth/account-exists-with-different-credential"
  5. This authErr should be with type AuthError but doesn't have the properties (like email) in official doc
  6. In the productive module node_modules\@firebase\auth\dist\auth-public.d.ts, this type is defined same as official doc,

Relevant Code:

These following two points are the reason why I think AuthError Class needs a change.

  • Current master branch code for AuthError, extending FirebaseError

    export interface AuthError extends FirebaseError {
    /** The name of the Firebase App which triggered this error. */
    readonly appName: string;
    /** The email of the user's account, used for sign-in/linking. */
    readonly email?: string;
    /** The phone number of the user's account, used for sign-in/linking. */
    readonly phoneNumber?: string;
    /**
    * The tenant ID being used for sign-in/linking.
    *
    * @remarks
    * If you use {@link signInWithRedirect} to sign in,
    * you have to set the tenant ID on {@link Auth} instance again as the tenant ID is not persisted
    * after redirection.
    */
    readonly tenantid?: string;
    }

  • Current FirebaseError type definition, with optional customData but no email,phoneNumber, etc.

    export class FirebaseError extends Error {
    readonly name = ERROR_NAME;
    constructor(
    readonly code: string,
    message: string,
    public customData?: Record<string, unknown>
    ) {
    super(message);
    // Fix For ES5
    // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
    Object.setPrototypeOf(this, FirebaseError.prototype);
    // Maintains proper stack trace for where our error was thrown.
    // Only available on V8.
    if (Error.captureStackTrace) {
    Error.captureStackTrace(this, ErrorFactory.prototype.create);
    }
    }
    }

  • Code for reproduce error, step 4 and step 5

try {
  const ghAccessToken = await signInWithPopup(auth, ghaProvider);
} catch (err: any) {
  if (err.code === FireAuthErrorCode.NEED_CONFIRMATION) {
    for (let k of Object.getOwnPropertyNames(err)) {
      console.log("error", k, err[k]);
      /*  Here it shows clearly that the err doesn't have the properties of `AuthError`.
      Instead, it has a customData field with same properties extended in `AuthError`  */
    }
  } else {
    console.error("uncaught Error");
    throw err;
  }
}

I wrote this feedback on official doc

  • detail
    When I use "firebase": "^9.1.2" with TypeScript, the err, thrown from signInWithPopup with error code AuthErrorCodes.NEED_CONFIRMATION === "auth/account-exists-with-different-credential", has the same structure as Firebase error with fields {code,name,message,stack}. The extended part is a customData property. customData is an Object with properties: {appName, email, _tokenResponse}. My currUser doesn't have phoneNumber or tenantId(because I'm using popup not redirect).

  • what I think it should be

  • Class AuthError extends FirebaseError with Properties:
    customData, with type AuthErrorData(Object)

  • Class AuthErrorData extends Object with properties in this paged

@PabloLION
Copy link
Contributor Author

Please, before closing this issue, remember to edit the official document mentioned here above (same link in #5600).

@jbalidiong jbalidiong added the v9 label Oct 11, 2021
@PabloLION
Copy link
Contributor Author

Added 2 tasks to make the follow-up more obvious/readable.

@PabloLION
Copy link
Contributor Author

This is cloesd by #5616

@firebase firebase locked and limited conversation to collaborators Dec 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants