ionic, firebase: jak uzyskać wszystkie e-maile użytkowników z uwierzytelniania firebase

Dec 28 2020

Próbuję uzyskać adresy e-mail użytkowników WSZYSTKICH użytkowników znajdujących się w moim magazynie uwierzytelniania w Firebase. Potrzebuję tych informacji, aby umożliwić użytkownikom wysyłanie wiadomości w systemie. nie mam dużego doświadczenia z jonami, więc wybacz mi, jeśli to głupie pytanie. nie potrzebuję adresu e-mail zalogowanych użytkowników, mam już do niego dostęp, ale mam problem z dostępem do nich wszystkich.

kod logowania, nie wiem, czy dokładnie jest potrzebny.

// 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');
  }

}

kod rejestracji

// 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');
  }


}

to, co próbuję uzyskać, byłoby czymś w rodzaju

  1. użytkownik klika listę / opcje
  2. użytkownik wybiera jeden e-mail
  3. wpisze treść wiadomości, którą chce udostępnić, udostępnię mały fragment
<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.

zrzut ekranu usługi uwierzytelniania

Odpowiedzi

FrankvanPuffelen Dec 28 2020 at 00:42

W pakiecie SDK uwierzytelniania Firebase po stronie klienta nie ma możliwości uzyskania adresów e-mail wszystkich użytkowników w systemie, ponieważ stanowiłoby to potencjalne zagrożenie bezpieczeństwa.

Jeśli Twoja aplikacja potrzebuje tej funkcji, musisz ją stworzyć samodzielnie. Dwie najczęstsze opcje to:

  1. Zaimplementuj niestandardowy interfejs API po stronie serwera, który korzysta z pakietu Firebase Admin SDK, który ma taką funkcjonalność.
  2. Przechowuj niezbędne dane użytkownika w bazie danych, takiej jak baza danych czasu rzeczywistego Firebase lub Cloud Firestore, i pozwól klientowi uzyskać do niej dostęp.

W obu przypadkach aplikacja kontroluje, jakie dane o użytkownikach są ujawniane, co rozwiązuje problem dotyczący bezpieczeństwa.

Zobacz także:

  • Pobieranie listy użytkowników, którzy zarejestrowali się przy użyciu uwierzytelniania Firebase
  • Uzyskaj listę adresów e-mail użytkowników dzięki AngularFire
  • Jak pobrać wszystkie zarejestrowane e-maile uwierzytelniające w Firebase