Reputation: 107
I am trying to confirm the user password again before the user tries to change the password.
Currently, my Firebase Auth project is configured in Firebase.js and is exported correctly
//appConfig = ...(all the configurations here)
const app = firebase.initializeApp(appConfig);
const projectAuth = app.auth()
export { projectAuth }
And in my PasswordManager.js, I use that exported projectAuth:
import { projectAuth } from "../firebase";
const authenticateCurrentPassword = async (currentPassword) => {
try {
const cred = projectAuth.EmailAuthProvider.credential(
projectAuth.currentUser.email, currentPassword);
projectAuth.reauthenticateWithCredentials(cred)
await projectAuth.reauthenticateAndRetrieveDataWithCredential(cred);
dispatchIfNotCancelled( {type: 'AUTHENTICATED'})
return true
}
catch (err) {
console.log(err)
dispatchIfNotCancelled( {type: 'ERROR'})
}
}
On the line where I am trying to initialize the "cred", it gives me an error saying that credential doesn't exist:
"TypeError: Cannot read properties of undefined (reading 'credential')"
I know that credential is a function inside EmailAuthProvider.
btw: I'm using "firebase": "^7.24.0"
, if that does any help.
Upvotes: 2
Views: 3734
Reputation: 83
this is what worked for me mind you am using angular 13 with angular/fire 7.2
i imported EmailAuthProvider
direcly from 'firebase/auth'
so my code looked like const credentials = EmailAuthProvider.credential(user.email, password.old);
i hope this helps
Upvotes: 3