【发布时间】:2021-08-10 00:18:53
【问题描述】:
如果有签名用户,我想使用 getServerSideProps 在 Firestore 中获取“示例”文档。 下面的代码不起作用。结果是“无法阅读” 我该怎么办?还是有其他方法?
export const getServerSideProps = () => {
let currentUser = []
authService.onAuthStateChanged(async user => {
if(user) {
const docRef = dbService.collection('whole_users').doc('sample').get()
await docRef.then((doc) => {
if(doc.exists) {
currentUser.push(doc.data())
}
})
} else {
console.log("can't read")
}
})
return {
props: {currentUser}
}
}
【问题讨论】:
-
这一行的用户是从哪里传来的?
authService.onAuthStateChanged(async user => {您是否尝试注销用户值? -
它只是“onAuthStateChanged”参数。如果“onAuthStateChanged”中有数据,我尝试将数据放入 currentUser。
标签: javascript firebase-authentication next.js