我希望当我加入例如 user1 和 user1 购买游轮时,它会在个人资料中显示 user1 购买的所有游轮,但是当我进入页面时它会显示该错误,这是我的代码:
perfil.page.html
<div class="ion-page" id="main-content">
<ion-header>
<ion-toolbar color="primary">
<ion-buttons slot="start">
<ion-menu-button></ion-menu-button>
</ion-buttons>
<ion-title>Perfil</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<div class="perfil">
<ion-avatar>
<img src="https://ionicframework.com/docs/img/demos/avatar.svg"/>
</ion-avatar>
</div>
<div class="align-center">
<ion-title>Nombre</ion-title>
</div>
<p></p>
<ion-item class="titulo" color="primary">
<ion-title>Cruceros Reservados</ion-title>
</ion-item>
<ion-list>
<ion-item *ngFor="let crucero of crucerosReservados">
<ion-label>{{ crucero.nombreCrucero }}</ion-label>
</ion-item>
</ion-list>
<ion-item class="titulo" color="primary">
<ion-title>Cruceros Visitados</ion-title>
</ion-item>
<ion-item class="titulo" color="danger" button (click)="logout()">
<ion-title>Cerrar Sesión</ion-title>
</ion-item>
</ion-content>
</div>
perfil.page.ts
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { IonicModule } from '@ionic/angular';
import { Router, RouterLink } from '@angular/router';
import { AuthenticationService } from '../authentication.service';
import { MenuController } from '@ionic/angular';
import { GlobalService } from '../global.service';
import { ReservasService } from '../reservas.service';
@Component({
selector: 'app-perfil',
templateUrl: './perfil.page.html',
styleUrls: ['./perfil.page.scss'],
standalone: true,
imports: [CommonModule, FormsModule, IonicModule, RouterLink]
})
export class PerfilPage {
user: any
crucerosReservados: any[] = [];
constructor(public authService:AuthenticationService, public router: Router, public menu: MenuController, public globalService: GlobalService, private reservasService: ReservasService) {
this.menuActive();
this.loadUserProfile();
}
menuActive(){
this.menu.enable(true, 'menu');
}
async loadUserProfile() {
const user = await this.authService.loginUser('[email protected]', 'password');
this.user = user.user;
this.globalService.uid = this.user.uid;
this.loadCrucerosReservados();
}
async loadCrucerosReservados() {
if (this.globalService.uid) {
this.crucerosReservados = await this.reservasService.obtenerReservasPorUid(this.globalService.uid);
}
}
async logout(){
this.authService.signOut().then(() => {
this.router.navigate(['/login'])
})
}
}
身份验证.service.ts
import { inject, Injectable } from '@angular/core';
import { Auth } from '@angular/fire/auth';
import { createUserWithEmailAndPassword, sendPasswordResetEmail, signInWithEmailAndPassword, signOut, User } from 'firebase/auth';
import { GlobalService } from './global.service';
@Injectable({
providedIn: 'root',
})
export class AuthenticationService {
private auth = inject(Auth);
constructor( public globalService: GlobalService ) { }
async registerUser(email: string, password:string){
return await createUserWithEmailAndPassword(this.auth, email, password)
}
async loginUser(email: string, password: string){
return await signInWithEmailAndPassword(this.auth, email, password)
}
async resetPassword(email: string){
return await sendPasswordResetEmail(this.auth, email)
}
async signOut(){
return await signOut(this.auth)
}
}
全局.service.ts
import { Injectable } from "@angular/core";
@Injectable({
providedIn: 'root',
})
export class GlobalService {
public uid: string = '';
public usuario: {};
async inicializarGlobales() {
this.uid = '';
this.usuario = {};
}
constructor() {}
}
reservas.service.ts
import { inject, Injectable } from "@angular/core";
import { addDoc, collection, query, Firestore, getDocs, where } from "@angular/fire/firestore";
@Injectable({
providedIn: 'root',
})
export class ReservasService {
private firestore = inject(Firestore);
constructor( ) { }
async guardarReserva(uid: any, fechaInicio: any, lugares: any, puertoSalida: any, noches: any, huespedes: any, nombreCamarote: any, numeroCamarotes: any, nombreCrucero: any) {
const obj ={
"uid" : uid,
"fechaInicio" : fechaInicio,
"lugares" : lugares,
"puertoSalida" : puertoSalida,
"noches" : noches,
"huespedes" : huespedes,
"nombreCamarote" : nombreCamarote,
"numeroCamarotes" : numeroCamarotes,
"nombreCrucero" : nombreCrucero
};
const Ref = collection(this.firestore, 'Reservas');
await addDoc(Ref, obj);
}
async obtenerReservasPorUid(uid: string) {
const Ref = collection(this.firestore, 'Reservas');
const q = query(Ref, where('uid', '==', uid));
const querySnapshot = await getDocs(q);
const reservas = querySnapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));
return reservas;
}
}
usuario.service.ts
import { inject, Injectable } from '@angular/core';
import { addDoc, collection } from 'firebase/firestore';
import { Firestore } from '@angular/fire/firestore'
import { GlobalService } from './global.service';
@Injectable({
providedIn: 'root',
})
export class UsuarioService {
private firestore = inject(Firestore);
constructor(public globalService: GlobalService) {}
async guardarDatosUsuario(nombre: string, email:string){
const obj = {
"uid" : this.globalService.uid,
"nombre" : nombre,
"email" : email,
};
const Ref = collection(this.firestore, 'Usuario');
await addDoc(Ref, obj);
}
}
firebase 文档提供了有关您的错误的更多信息:https://firebase.google.com/docs/auth/admin/errors
用于验证管理 SDK 的凭据不能用于执行所需的操作。某些身份验证方法(例如 createCustomToken() 和 verifyIdToken())要求使用证书凭据(而不是刷新令牌或应用程序默认凭据)来初始化 SDK。请参阅初始化 SDK,获取有关如何使用证书凭证对管理 SDK 进行身份验证的文档。