0

I have a problem logging into the firebase realtime database... I'm desperate because I've tried everything... but it gives me an error... I need the query to have orderby

introducir el código aquí
let headers = new HttpHeaders({
              'Content-Type': 'application/json'});
 headers = headers.append('Authorization', 'Bearer ' + token);
          const url = `https://hola-default-rtdb.europe-west1.firebasedatabase.app/d`;

           const urlABorrar = `${url}.json?orderBy="id"&equalTo="${codigo}"`;


           const reqHeader = new HttpHeaders().set('Authorization', 'Bearer ' + token);

           this.httpCliente.get(urlABorrar,{headers: reqHeader})-

    

  {
    
    "rules": {
    
      ".read": "auth.uid!= null",
      ".write": "auth.uid!= null",
          "data": {
            ".indexOn": ["id"]
          
          }
  
    }
  }
2
  • Hola!, te recomiendo agregar paqueteria que usas ya que ha cambiado en su ultima versión y también la manera en que ingresas tus credencialespara concetar la app a Firebase... ya que puntualmente tu problema es de conexión... no las Keys, el código que usas para conectar
    – Julio Daza
    el 1 abr. a las 22:19
  • ok que tipo de paqueteria.... la firebase para realdatabase ? .... gracias el 2 abr. a las 9:48

1 respuesta 1

0

no se si seas nuevo en la comunidad, pero debes darnos contexto para poder responderte adecuadamente, para este caso en particular versión de paquete y como configuraste la conexión a Firebase. Dicho esto te comparto ejemplo de codigo real de una app que tengo que funciona, esta en una angular v12, pero seria útil de ejemplo. para que valides si tienes estas configuraciones hechas, ya que un error 400 significa que tienes mal configurado algo.

packageJson:

 "dependencias": {
  ....
  "@angular/fire": "^6.1.5",
  "firebase": "^8.6.8"
  
  ....
  }

Configuración de AppModule con librería de AngularFire:

@NgModule({
   declarations: [AppComponent],
   imports: [
   ....
   AngularFireModule.initializeApp(environment.firebaseConfig),
   ....
   ],
   bootstrap: [AppComponent],
})
export class AppModule {}

y en el environments.ts:

export const environment = {
   ....
   firebaseConfig: {
      apiKey: "DKHFBGSEIHFNGFGAWSDG",
      authDomain: "tuconfig.firebaseapp.com",
      projectId: "tunameproyect",
      storageBucket: "tustorebucket",
      messagingSenderId: "tummessagesender id",
      appId: "tuappid"
   }
   ...
}

y el servicio que se colgaba de FireBase luce así:

import {
        AngularFirestore,
        AngularFirestoreCollection,
        AngularFirestoreDocument,
       } from "@angular/fire/firestore";


    @Injectable({
        providedIn: "root",
     })
    export class FirebaseNotificationsService {
    ...
       //trae info de collecciones de Firebase
       getDbFirebase(filter: string = null) {
         if (filter) {
         this.db = this.angularFire.collection("notification_realtime", 
         (ref) =>
           ref.where("userId", "==", this.adminId).where("state", "==", 
         filter));
        } else {
         this.db = this.angularFire.collection("notification_realtime", 
         (ref) => ref
                 .where("userId", "==", this.adminId)
                 .where("state", "==", "delivered")
         );
       }
      }


     //este si se conecta a realtime
      getNotifications(filter: string = null) {
        this.getDbFirebase(filter);
         return this.db.snapshotChanges().pipe(
          map((actions) =>
            actions.map((a) => {
               const data = a.payload.doc.data() as Notifications;
               const id = a.payload.doc.id;
            return { id, ...data };
          })
         )
       );
      }
    ...
    }

Te anexo un tuto de Medium mas reciente: https://medium.com/ignite-ui/firebase-angular-application-with-auth-and-realtime-database-ae37fef5859d

Y el repo en github que se conecta desde ANgular 15: https://github.com/IgniteUI/crypto-portfolio-app

Espero que esto te de ayuda.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.