[英]Property 'auth' does not exist on type 'typeof import..." firebase/auth
[英]Firebase updateProfile does not exist on type 'User'
对于最终的学校项目。 我必须使用 firebase 创建某种待办事项应用程序作为数据库和身份验证工具。 我允许某种用户名更改,以便人们可以发挥创意。 在主屏幕上,有一个带有欢迎标志的仪表板。 在用户没有用户名之前,会显示当前的 UID。 您可以使用表单更改此设置。 关键是当我想编写代码来更新用户的用户名时,我收到一条错误消息:
“用户”类型上不存在属性“updateProfile” 。
我觉得这很奇怪,因为我按照原始 firebase 文档中记录的方式实现代码。 有没有人可以查看是否存在错误或解决问题的线索?
现在我已将代码放入 onAuthStateChanged-codeblock 中,这样我就可以获得用户的实际凭据而不是 null..。 理想情况下,代码在另一个块中分开
const userCred = () => {
onAuthStateChanged(auth, (user) => {
if (user) {
const { uid } = user;
const userPlaceholder = document.querySelector<HTMLHeadElement>('#dashboardName');
const displaynamePlaceholder = document.querySelector<HTMLInputElement>('#displaynameInput');
console.log(userPlaceholder);
if (user.displayName !== null) {
userPlaceholder!.innerHTML = `Welcome ${user.displayName}`;
displaynamePlaceholder!.setAttribute('value', `${user.displayName}`);
} else {
userPlaceholder!.innerHTML = `Welcome ${uid}`;
displaynamePlaceholder!.setAttribute('value', `${uid}`);
userPlaceholder!.style.fontSize = '1.6rem';
}
}
const displaynamePlaceholder = document.querySelector<HTMLInputElement>('#displaynameInput')?.value;
user?.updateProfile({
displayName: String(displaynamePlaceholder),
photoURL: null,
});
});
console.log('not logged in');
};
这是我的代码:
这可能是因为您在应用中使用 Firebase v9 时查看了 Firebase v8 文档。 根据 firebase v9用户文档, User
中不再有updateProfile
方法。 它现在是一个独立的功能,这里是文档。
import { getAuth, updateProfile } from "firebase/auth";
const auth = getAuth();
updateProfile(auth.currentUser, {
displayName: "Jane Q. User", photoURL: "https://example.com/jane-q-user/profile.jpg"
}).then(() => {
// Profile updated!
// ...
}).catch((error) => {
// An error occurred
// ...
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.