我正在嘗試在 fireBase fireStore 中添加一個集合,所以我使用了這個函式 .collection.(doc).set ;該集合未創建,控制臺顯示錯誤注冊,盡管我在 firebase 中找到了新用戶進行身份驗證,但我希望找到好的解決方案。我快瘋了
export class RegisterComponent implements OnInit {
constructor(private as:AuthService , private fs:AngularFirestore , private route:Router) { }
ngOnInit(): void {
}
register(f){
// console.log(f.value)
let data=f.value
this.as.signUp(data.email,data.password ).then((user)=>{
this.fs.collection("users").doc(user.user.uid).set({
firstName:data.firstName,
email:data.email,
bio:data.bio,
uid:data.user.user.uid
})
.then(()=>{
console.log('done')
// this.route.navigateByUrl('/home')
})
})
.catch(()=>{
console.log('error register')
})
}
}
uj5u.com熱心網友回復:
你沒有在你的鏈中回傳承諾,所以你的代碼被他們吹走了。如果這不能解決您的問題,那么問題出在您的signUp代碼中,您必須發布該代碼以獲得更多幫助。
register(f){
let data=f.value
this.as.signUp(data.email, data.password).then((user) => {
// You need to return this promise. Right now, your code
// is blowing right by it and immediately calling the next `then`
return this.fs.collection("users").doc(user.user.uid).set({
firstName: data.firstName,
email: data.email,
bio: data.bio,
uid: data.user.user.uid
})
}).then(() => {
// This code block has now waited for the doc to be set
console.log('done')
// this.route.navigateByUrl('/home')
}).catch((error) => {
console.log('error register')
console.log(error)
})
}
uj5u.com熱心網友回復:
它仍然無法正常作業,并且出現相同的錯誤 user is undefined ,希望此注冊功能代碼可以提供幫助
export class AuthService {
user: Observable<firebase.User>;
constructor(private fa:AngularFireAuth) {
this.user=this.fa.user
}
signUp(email,password){
return this.fa.createUserWithEmailAndPassword(email,password)
}
signIn(email,password){
return this.fa.signInWithEmailAndPassword(email,password)
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/352690.html
標籤:javascript 有角的 数据库 火力基地 谷歌云firestore
