【发布时间】:2018-09-18 05:24:20
【问题描述】:
我正在使用来自 javascript 客户端的 Firebase 身份验证进行测试,我正在尝试使用 retrieve id tokens on clients documentation 检索 idToken
我想我忘记了一些基本的东西。
用户使用 Google 登录
代码只是我在其他帖子和文档中看到的。结果在 cmets 中。
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
console.log(user); // this is shown. Firebase user and provider data
console.log(user.uid); // Shown
firebase.auth().user.getIdToken().then(function(idToken) {
console.log(idToken+'--'); // Nothing happens. No errors and the function not continues
});
console.log(user.uid); // Nothing happens
}
})
谢谢
编辑:
如果我添加任何错误,也不会发生任何事情。例如,如果我添加一个警报,它会显示警报,但如果我有错误,例如 alter() 不会显示任何错误。添加了捕获,什么也没有
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
alter() // Nothing happens and the function stop
console.log(user); // this is shown. Firebase user and provider data
console.log(user.uid); // Shown
firebase.auth().user.getIdToken().then(function(idToken) {
console.log(idToken+'--'); // Nothing happens. No errors and the function not continues
}).catch(function(error) {
console.log(error+'--'); // Nothing
});
console.log(user.uid); // Nothing happens
}
})
【问题讨论】:
-
根据文档,它是
firebase.auth().currentUser.getIdToken(),而不是像你这里的firebase.auth().user。试试看是否能解决问题,如果没有,请更新您的问题 -
试过了。结果相同。我从其他帖子中获得了代码,他们说有效。和这个一样。 stackoverflow.com/questions/39799588/…
标签: javascript firebase web firebase-authentication