firebaseui-web icon indicating copy to clipboard operation
firebaseui-web copied to clipboard

Unable to access typing for firebaseui.auth.AuthResult when using signInSuccessWithAuthResult callback

Open mcfarljw opened this issue 2 years ago • 4 comments

Describe your environment

  • Operating System version: macOS 12.1
  • Browser version: Chrome 96
  • Firebase UI version: 6.0.0
  • Firebase SDK version: 9.2.0

Describe the problem

The signInSuccessWithAuthResult callback returns authResult as any rather than of type firebaseui.auth.AuthResult. There also appears to be no way to access a typing for firebaseui.auth.AuthResult to manually apply the typing.

Additional information

This is a duplicate of https://github.com/firebase/firebaseui-web/issues/680 but I'm opening it as a bug as a prolonged amount of time has passed and it seems more like a bug than a feature request at this time. There is a lot of useful information contained within the AuthResult which can currently only be found by looking at snippets in the library or doing a console.log to see what it actually returns. I was looking for authResult.additionalUserInfo.isNewUser to determine if it was a new or existing user which would have been much easier if there was a typing.

mcfarljw avatar Jan 01 '22 16:01 mcfarljw

I ran into this issue as well and wanted to provide more info.

You'll find this comment for the type... tslint:disable-next-line:no-any firebase dependency not available.

Which indicates to me the returned type depends on the version of Firebase SDK you're using with this library.

To make TS happy I specified the type on the signInSuccessWithAuthResult function as follows.

(authResult: {user: User}) => {..}

And User comes from...

import {User} from "firebase/auth" - for v9

I'm only using User but you can add whatever you're using.

jheyer159 avatar Jan 11 '22 18:01 jheyer159

Thanks @jheyer159 for the tip of looking in firebase/auth for at least pieces that can be used to recreate the AuthResult based on the Firebase SDK version being used. That is certainly better and more useful than using any.

It might be sufficient to just have this mentioned in the README.

mcfarljw avatar Jan 11 '22 19:01 mcfarljw

These are the typescript types of firebaseui-web 6.0.0

interface Callbacks {
  signInSuccessWithAuthResult?(
    // tslint:disable-next-line:no-any firebase dependency not available.
    authResult: any,
    redirectUrl?: string
  ): boolean;
  signInFailure?(error: firebaseui.auth.AuthUIError): Promise<void>|void;
  uiShown?(): void;
}

Does anybody know the type of authResult when using it with firebase v9? It seems not to be an ordinary UserCredential. getAdditionalUserInfo(authResult) gives me null, but authResult.additionalUserInfo is available.

henrik-d avatar Feb 08 '22 10:02 henrik-d

I'm also running into typing issues as it relates to the AuthResult. It seems that firebaseui is still using the compat types from firebase, which I believe are to match up with v8 APIs? I am trying to make use of the v9 firebase APIs and am unable to map from one type to the other without all kinds of typing errors and property issues.

v9 - modular 'firebase/auth' UserCredential: export declare interface UserCredential { /** * The user authenticated by this credential. / user: User; /* * The provider which was used to authenticate the user. / providerId: string | null; /* * The type of operation which was used to authenticate the user (such as sign-in or link). */ operationType: typeof OperationType[keyof typeof OperationType]; }

'firebase/compat' firebase.auth.UserCredential: type UserCredential = { additionalUserInfo?: firebase.auth.AdditionalUserInfo | null; credential: firebase.auth.AuthCredential | null; operationType?: string | null; user: firebase.User | null; };

The second one is what is returned as the AuthResult from firebaseui.

Is firebasui going to convert to the v9 modular APIs?

kpaxton avatar Mar 01 '23 19:03 kpaxton