I am using Firebase authentication with AngularFire2
on an Ionic-Angular project. I need to be able to reauthenticate my users when needed, and it seems like the only way to do so is by obtaining the user's credentials, which can only be obtained through firebase.auth.EmailAuthProvider
, an object which isn't part of AngularFire
, but only of firebase
itself.
I am using firebase v8 for this, on which the EmailAuthProvider
object should be found in firebase.default.auth.EmailAuthProvider
. However, I get that firebase.default.auth
is undefined, and am therefore unable to access EmailAuthProvider
. The only solution I've found is to revert back to firebase v7, in which the latter can be successfully accessed through firebase.auth.EmailAuthProvider
. I cannot upgrade yet to firebase v9 for other compatibility issues, nor want to keep v7 as it gives me loads of high and medium vulnerabilities.
EDIT
I obtain the credentials in this manner:
import * as firebase from "firebase/app";
...
firebase.default.auth.EmailAuthProvider.credential(email, password)
And I get the following error:
Uncaught TypeError: Cannot read properties of undefined (reading 'EmailAuthProvider')
My package.json file has "@angular/fire": "^6.1.5"
and "firebase": "^8.10.0"
TLDR
In Firebase v8, how to access EmailAuthProvider
, or more generally, how to reauthenticate a user?
CodePudding user response:
Try changing your imports as shown below:
import firebase from "firebase/app";
import "firebase/auth" // <-- make sure you have auth imported
Then access EmailAuthProvider like this:
firebase.auth.EmailAuthProvider.credential(email, password)