У меня есть два приложения для двух типов пользователей;водители и пассажиры с отдельными узлами в одной базе данных Firebase в реальном времени с аутентификацией по электронной почте и паролю. в настоящее время драйвер может войти в приложение пользователя, но не будет иметь никакой информации, связанной с пользователемКак сделать так, чтобы гонщик вошел в систему для поиска UID только в узле гонщиков, а водители - только в узле водителей? он должен вернуть ошибку.
Я пытался отредактировать правила firebase, чтобы блокировать через uid, но в итоге он блокирует всех.
это мой код login.ts
login() {
if (this.email.length == 0 || this.password.length == 0) {
this.commonService.showAlert("Invalid Credentials");
}
else {
this.commonService.showLoader('Authenticating...');
this.authService.login(this.email, this.password).then(authData => {
this.commonService.hideLoader();
this.router.navigateByUrl('/home');
}, error => {
this.commonService.hideLoader();
this.commonService.showToast(error.message);
});
}
}
и авторизация. service.ts
// get current user data from firebase
getUserData() {
return this.afAuth.auth.currentUser;
}
// get passenger by id
getUser(id) {
return this.db.object('passengers/' + id);
}
// login by email and password
login(email, password) {
return this.afAuth.auth.signInWithEmailAndPassword(email, password);
}
resetPassword(email) {
return this.afAuth.auth.sendPasswordResetEmail(email);
}
sendVerificationEmail() {
return this.afAuth.auth.currentUser.sendEmailVerification();
}
logout() {
return this.afAuth.auth.signOut();
}
// register new account
register(email, password, name, phoneNumber) {
return Observable.create(observer => {
this.afAuth.auth.createUserWithEmailAndPassword(email, password).then((authData: any) => {
let userInfo: any = {
uid: authData.user.uid,
name: name,
phoneNumber: phoneNumber,
isPhoneVerified: false,
email: email
};
if (EMAIL_VERIFICATION_ENABLED === true)
this.getUserData().sendEmailVerification();
// update passenger object
this.updateUserProfile(userInfo);
observer.next();
}).catch((error: any) => {
if (error) {
observer.error(error);
}
});
});
}
процесс входа в систему должен быть следующим:
login() => check for uid in /passengers
if found => do normal rider thing
else => throw error
Database structure:
![enter image description here](https://i.stack.imgur.com/Y5FiP.png)
и наоборот для водителей,сейчас проверяется любой идентификатор. и регистрирует водителя в приложении райдера с такой информацией о гонщике, как фотографии и номер, пропущенный. бросая другие ошибки тоже.