【发布时间】:2022-11-07 20:09:06
【问题描述】:
我在我的 React 应用程序中使用 TypeScript,但出现错误“'用户'类型上不存在属性'accessToken'”当获得accessToken 的用户时
我在组件中的处理函数:
const handleRegister = (email: string, password: string) => {
const auth = getAuth();
createUserWithEmailAndPassword(auth, email, password)
.then(({user}) => {
dispatch(setUser({
email: user.email,
token: user.accessToken,
id: user.uid
}));
});
}
在寻找解决此问题的方法后,我这样做了
token: (user as unknown as OAuthCredential).accessToken,
并且 IDE 自动添加了以下导入
import firebase from "firebase/compat";
import OAuthCredential = firebase.auth.OAuthCredential;
但在那之后我在控制台中得到一个错误“未捕获的 ReferenceError:未定义 firebase”. 我觉得很愚蠢,但我不明白如何解决它
【问题讨论】:
-
accessToken属性确实存在于响应中,但在User接口和documentation 中都缺少。最好也将问题发布到Github。
标签: reactjs typescript firebase firebase-authentication