Чтобы просто решить вашу проблему, попробуйте передать kewirusType
из формы в updateUserData, например:
- передать kewirus этому методу:
async EmailRegister(email: any, password: any, displayName: any, kewirusType: string) {
return this.afAuth.auth.createUserWithEmailAndPassword(email, password)
.then((result) => {
result.user.updateProfile({
displayName: displayName,
photoURL: ''
}).then(() => {
this.updateUserData(result.user, kewirusType);
// this.SendVerificationMail();
this.router.navigateByUrl('/pages/projects/all-project');
window.alert("You have been successfully registered!");
console.log(result.user)
});
}).catch((error) => {
window.alert(error.message)
})
}
и
updateUserData
:
private updateUserData(user, kewirusType: string) {
// Sets user data to firestore on login
const userRef: AngularFirestoreDocument<User> = this.afs.doc(`users/${user.uid}`);
const data = {
uid: user.uid,
email: user.email,
displayName: user.displayName,
photoURL: user.photoURL,
emailVerified: user.emailVerified,
kewirusType //notice change here
}
return userRef.set(data, { merge: true })
}
ДОПОЛНИТЕЛЬНО:
Вместо создания этих данных в своем приложении рассмотрите возможность использования firebase functions для создания user/{uuid}
документа, например:
export const initUserData = functions.auth.user().onCreate((user) => {
const collectionDoc = admin.firestore().collection(`users`);
return collectionDoc.doc(user.uid).set({
uid: user.uid,
email: user.email,
kewirusType: "value"
//... your data here
}).then(() => {
console.log(`Data for user ${user.uid} initialized`);
});
});
Затем в своем приложении вы можете просто подписать /user/{uuid}
документ, чтобы получить данные пользователя. Лучше и безопаснее делегировать такие процессы за пределы приложения.
Функция Firebase имеет доступ к каждой службе Firebase (аутентификация, документы, хранилище и т. Д. c), поэтому в основном вы можете многое с ней сделать.