admin管理员组文章数量:1361960
Not exactly sure what I am doing wrong here, I have looked at other forum post and this is what they say to do to re-auth a user. But I am getting an error of:
TypeError: Cannot read property 'credential' of undefined
on this line here:
const credentials = fire.auth.EmailAuthProvider.credential(currentUser.email, user.currentPass);
Here is the code:
const currentUser = fire.auth().currentUser;
const credentials = fire.auth.EmailAuthProvider.credential(currentUser.email, user.currentPass);
currentUser
.reauthenticateWithCredential(credentials)
.then(() => {
alert('Success');
})
.catch(err => {
alert(err);
});
Not exactly sure what I am doing wrong here, I have looked at other forum post and this is what they say to do to re-auth a user. But I am getting an error of:
TypeError: Cannot read property 'credential' of undefined
on this line here:
const credentials = fire.auth.EmailAuthProvider.credential(currentUser.email, user.currentPass);
Here is the code:
const currentUser = fire.auth().currentUser;
const credentials = fire.auth.EmailAuthProvider.credential(currentUser.email, user.currentPass);
currentUser
.reauthenticateWithCredential(credentials)
.then(() => {
alert('Success');
})
.catch(err => {
alert(err);
});
Share
Improve this question
edited Jan 15, 2018 at 21:34
Taylor Austin
asked Jan 15, 2018 at 21:19
Taylor AustinTaylor Austin
6,02716 gold badges63 silver badges108 bronze badges
10
-
How are you defining
fire
here? – bojeil Commented Jan 15, 2018 at 22:25 -
const fire = firebase.initializeApp(config);
, Everything else is working for the fire part, like the currentUser works just fine etc... – Taylor Austin Commented Jan 15, 2018 at 22:37 -
1
That explains it. Update the above to:
firebase.auth.EmailAuthProvider.credential(...)
. – bojeil Commented Jan 16, 2018 at 0:54 -
4
It is not the same thing. If you are doing:
const firebase = require('firebase');
you should usefirebase.auth.EmailAuthProvider
. This is defined under the firebase namespace. It is not an instance method. – bojeil Commented Jan 16, 2018 at 19:13 - 1 @Rai checkout my answer – somejhereandthere Commented Nov 1, 2018 at 16:34
3 Answers
Reset to default 4Like @bojeil answered, it's a namespace so, for instance and if you're using typescript and you used firebase.initializeApp(config);
in another class, just add again the import in the class where you user the credential method with import * as Firebase from 'firebase/app';
As u can see in the doc credential
it's a static method in a static class that's why you need the namespace.
You've imported firebase in the wrong way. Here is what it says in the document. Official Document
const firebase = require('firebase');
const cred = firebase.auth.EmailAuthProvider.credential(
email,
password
);
I had the same issue as you and none of these answers helped me.
This worked for me:
const cred = fire.firebase_.auth.EmailAuthProvider.credential(email, password);
I'm not entirely sure why, but I just tried all the options available on fire
in the dev tools until I came across firebase_ which had the option of EmailAuthProvider
. Maybe someone else here knows why.
本文标签:
版权声明:本文标题:javascript - TypeError: Cannot read property 'credential' of undefined with firebase reauthenticateWithCredentia 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743855895a2550849.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论