Utk*_*mte 5 firebase ecmascript-6 firebase-authentication
我正在尝试使用获取用户令牌
import { auth, database } from "firebase";
await token = await auth().currentUser.getIdToken();
Run Code Online (Sandbox Code Playgroud)
但相反,我收到了这个错误,
TypeError: Cannot read property 'getIdToken' of null
Run Code Online (Sandbox Code Playgroud)
它有时有效,但有时无效。我在这里做错了什么?
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
user.getIdToken().then(function(data) {
console.log(data)
});
}
});
Run Code Online (Sandbox Code Playgroud)