prescottprue / react-redux-firebase

Redux bindings for Firebase. Includes React Hooks and Higher Order Components.
https://react-redux-firebase.com
MIT License
2.55k stars 559 forks source link

bug(types): firebase.reauthenticate isn't working with TypeScript #909

Open alekseykarpenko opened 4 years ago

alekseykarpenko commented 4 years ago

Do you want to request a feature or report a bug?

Seems like a bug regarding the documentation

What is the current behavior? Actually I can't use reauthenticate() as described in docs.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via codesandbox or similar.

There are two problems regarding reauthenticate:

  1. It isn't provided in the outgoing interface for TypeScript, I'm currently facing this: TS2339: Property 'reauthenticate' does not exist on type 'ExtendedFirebaseInstance & ExtendedAuthInstance & ExtendedStorageInstance'. ~2. Even when adding //@ts-ignore, my App is falling with error that seems shouldn't be related: Application verifier is required for phone authentication But i'm trying to reauthenticate with email and password. not the phone:~ UPD: Okay, I previously tried to use it in a wrong way, but still to make it work I need three different ts-ignores:
    // #1
    // @ts-ignore
    const credential = firebase.auth.EmailAuthProvider.credential(user?.email, password);
    // #2
    // @ts-ignore
    return firebase.reauthenticate({credential})
      .then(() => {})
      // #3
      // @ts-ignore
      .catch((e) => { console.log(e); })

1 Is because of Property 'EmailAuthProvider' does not exist on type '() => FirebaseAuth'.

Removing #2 causes: Property 'reauthenticate' does not exist on type 'ExtendedFirebaseInstance & ExtendedAuthInstance & ExtendedStorageInstance'. And #3 stands for classic: Parameter 'e' implicitly has an 'any' type. as I don't know what type of error should be here

What is the expected behavior? I wan't to reauthenticate my user on security-sensitive actions using TypeScript and as described in docs: https://react-redux-firebase.com/docs/auth.html#logincredentials-and-reauthenticatecredentials

Which versions of dependencies, and which browser and OS are affected by this issue? Did this work in previous versions or setups?

"dependencies": {
    "react": "^16.13.1",
    "react-redux": "^7.2.0",
    "react-redux-firebase": "^3.3.0"
}
ghost commented 4 years ago

Having similar issue which is probably related : Property 'GoogleAuthProvider' does not exist on type '() => FirebaseAuth'.

prescottprue commented 4 years ago

Thanks for calling out - Right now we are just using () => AuthTypes.FirebaseAuth where AuthTypes comes from Firebase. I'll look into how they are doing the types for Auth since it should also include statics

prescottprue commented 4 years ago

I actually appears that part of what they are doing matches what we are doing, but there is some other types in there that we will need to match.

Would love a PR if anyone gets a chance, been a bit busy lately