【发布时间】:2021-05-24 20:53:39
【问题描述】:
我使用 vue 和 firebase 和 firestore
我在注册时会自动登录。 问题是自动登录后,我的名字需要刷新才能更新。
下面是描述的图片。
{{ user.displayName }}
created () {
firebase.auth().onAuthStateChanged((user) => {
if (user) {
this.user = user
} else {
this.user = ''
}
})
} in Navbar.vue
methods: {
async SignUp () {
await firebase.auth().createUserWithEmailAndPassword(this.user.email, this.user.password)
.then((res) => {
res.user.updateProfile({
displayName: this.user.name
})
const uid = firebase.auth().currentUser.uid
const createdAt = new Date()
db.collection('users').add(
{
name: this.user.name, email: this.user.email, createdAt, uid
}
)
alert('success!')
this.$router.push({ name: 'Home' })
})
}
} in register.vue
有没有办法不刷新就更新用户名?
如果我通过登录窗口登录,我不必刷新它。 如果我注册后通过自动登录登录,用户名不会出现。
【问题讨论】:
标签: vue.js google-cloud-firestore firebase-authentication