[英]ionic, firebase: How to get ALL user emails from firebase authentication
i'm trying to get the user email of ALL the users that are in my firebase authentication store, i need this information so i can allow user to message one another within the system.我正在尝试获取 firebase 身份验证存储中的所有用户的用户 email,我需要此信息,以便我可以允许用户在系统内互相发送消息。 im not very experienced with ionic so pardon me if it's a stupid question.
我对离子不是很有经验,所以如果这是一个愚蠢的问题,请原谅我。 i do not need the logged in users email, i already have access to it but am having trouble accessing all of them.
我不需要登录用户 email,我已经可以访问它,但无法访问所有这些用户。
login code, not sure if exactly needed.登录代码,不确定是否确实需要。
// 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');
}
}
register code注册码
// 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');
}
}
what i'm trying to get would be something like我想要得到的就像
<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.
There is no way in the client-side Firebase Authentication SDK to get the email addresses of all users in the system, as that would be a potential security risk.客户端Firebase Authentication SDK无法获取系统中所有用户的email地址,存在安全隐患。
If your app needs this functionality, you'll have to build it yourself.如果您的应用需要此功能,您必须自己构建它。 The two most common options are:
两个最常见的选项是:
In both cases your app controls what data is exposed about your users, which addresses the security concern.在这两种情况下,您的应用程序都可以控制向您的用户公开哪些数据,从而解决安全问题。
Also see:另见:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.