ionic, firebase: Cách nhận TẤT CẢ email của người dùng từ xác thực firebase
tôi đang cố lấy email người dùng của TẤT CẢ những người dùng có trong cửa hàng xác thực firebase của tôi, tôi cần thông tin này để có thể cho phép người dùng nhắn tin cho nhau trong hệ thống. Tôi không có nhiều kinh nghiệm với ion nên thứ lỗi cho tôi nếu đó là một câu hỏi ngu ngốc. Tôi không cần email của người dùng đã đăng nhập, tôi đã có quyền truy cập vào nó nhưng gặp sự cố khi truy cập tất cả chúng.
mã đăng nhập, không chắc chắn nếu chính xác cần thiết.
// login.page.ts
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
import { NavController } from '@ionic/angular';
import { AuthenticationService } from '../services/authentication.service';
@Component({
selector: 'app-login',
templateUrl: './login.page.html',
styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit {
validations_form: FormGroup;
errorMessage: string = '';
constructor(
private navCtrl: NavController,
private authService: AuthenticationService,
private formBuilder: FormBuilder
) { }
ngOnInit() {
this.validations_form = this.formBuilder.group({
email: new FormControl('', Validators.compose([
Validators.required,
Validators.pattern('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$')
])),
password: new FormControl('', Validators.compose([
Validators.minLength(5),
Validators.required
])),
});
}
validation_messages = {
'email': [
{ type: 'required', message: 'Email is required.' },
{ type: 'pattern', message: 'Please enter a valid email.' }
],
'password': [
{ type: 'required', message: 'Password is required.' },
{ type: 'minlength', message: 'Password must be at least 5 characters long.' }
]
};
loginUser(value) {
this.authService.loginUser(value)
.then(res => {
console.log(res);
this.errorMessage = "";
this.navCtrl.navigateForward('/welcome');
}, err => {
this.errorMessage = err.message;
})
}
goToRegisterPage() {
this.navCtrl.navigateForward('/register');
}
}
mã đăng kí
// register.page.ts
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
import { AuthenticationService } from '../services/authentication.service';
import { NavController } from '@ionic/angular';
@Component({
selector: 'app-register',
templateUrl: './register.page.html',
styleUrls: ['./register.page.scss'],
})
export class RegisterPage implements OnInit {
validations_form: FormGroup;
errorMessage: string = '';
successMessage: string = '';
validation_messages = {
'email': [
{ type: 'required', message: 'Email is required.' },
{ type: 'pattern', message: 'Enter a valid email.' }
],
'password': [
{ type: 'required', message: 'Password is required.' },
{ type: 'minlength', message: 'Password must be at least 5 characters long.' }
]
};
constructor(
private navCtrl: NavController,
private authService: AuthenticationService,
private formBuilder: FormBuilder
) { }
ngOnInit() {
this.validations_form = this.formBuilder.group({
email: new FormControl('', Validators.compose([
Validators.required,
Validators.pattern('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$')
])),
password: new FormControl('', Validators.compose([
Validators.minLength(5),
Validators.required
])),
});
}
tryRegister(value) {
this.authService.registerUser(value)
.then(res => {
console.log(res);
this.errorMessage = "";
this.successMessage = "Your account has been created. Please log in.";
}, err => {
console.log(err);
this.errorMessage = err.message;
this.successMessage = "";
})
}
goLoginPage() {
this.navCtrl.navigateForward('/login');
}
}
những gì tôi đang cố gắng đạt được sẽ như thế nào
- người dùng nhấp vào danh sách / tùy chọn
- người dùng chọn một email
- nhập bất kỳ nội dung tin nhắn nào mà anh ấy / cô ấy muốn chia sẻ, tôi sẽ chia sẻ một đoạn mã nhỏ
<ion-select>
<ion-select-option value="email1">email1</ion-select-option>
<ion-select-option value="email2">email2</ion-select-option>
<ion-select-option value="email3">email3</ion-select-option>
<ion-select-option value="email4">email4/ion-select-option>
</ion-select> //probably will use *ngFor to do this.
ảnh chụp màn hình dịch vụ xác thực
Trả lời
Không có cách nào trong SDK xác thực Firebase phía máy khách để lấy địa chỉ email của tất cả người dùng trong hệ thống, vì đó sẽ là một rủi ro bảo mật tiềm ẩn.
Nếu ứng dụng của bạn cần chức năng này, bạn sẽ phải tự xây dựng. Hai tùy chọn phổ biến nhất là:
- Triển khai API phía máy chủ tùy chỉnh sử dụng SDK quản trị Firebase, có chức năng như vậy.
- Lưu trữ dữ liệu người dùng cần thiết trong cơ sở dữ liệu, chẳng hạn như Cơ sở dữ liệu thời gian thực của Firebase hoặc Cloud Firestore và yêu cầu khách hàng truy cập vào cơ sở dữ liệu đó.
Trong cả hai trường hợp, ứng dụng của bạn kiểm soát dữ liệu nào được tiết lộ về người dùng của bạn, điều này giải quyết mối lo ngại về bảo mật.
Cũng thấy:
- Truy xuất danh sách người dùng đã đăng ký bằng Firebase Auth
- Nhận danh sách địa chỉ email của người dùng với AngularFire
- Cách tìm nạp tất cả các email xác thực đã đăng ký trong firebase