Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase and auth property does not exist in Ionic and Firebase

I am creating user-based content and button show using ionic 5 and the firebase app. I am going through on post and implement it in my application.

I and using : "firebase": "^8.1.1", "@angular/fire": "^6.1.3",

Now I got errors in auth() and firestore()

auth error is : Property 'auth' does not exist on type 'typeof import (TS-2339) AND firebase error is - Property 'firestore' does not exist on type 'typeof import

    import { Component, OnInit } from "@angular/core";
    import * as firebase from "firebase/app";
    import "firebase/auth";
    import "firebase/firestore";
     
    @Component({
      selector: "app-places",
      templateUrl: "./posts.page.html",
      styleUrls: ["./posts.page.scss"],
    })
    export class PlacesPage implements OnInit {
      constructor() {}
      //firestore = firebase.firestore();
      public isAdmin = false; 
      ngOnInit() {


    //Property 'auth' does not exist on type 'typeof import
            firebase.auth().onAuthStateChanged((user) => {
              if (user) {
                firebase


                  .firestore()    //Property 'firestore' does not exist on type 'typeof import
                 

 

    .doc(`s/${user.id}`)
                      .get()
                      .then((userProfileSnapshot) => {
                        this.isAdmin = userProfileSnapshot.data().isAdmin;
                      });
                  }
                });
       
        }
       }
  
like image 435
Pritesh Avatar asked Dec 01 '20 10:12

Pritesh


1 Answers

Please review the documentation for importing Firebase SDKs using a module bundler. Starting with Firebase SDK version 8.0.0, you now must import like this:

import firebase from "firebase/app";
import "firebase/auth";
import "firebase/firestore";

Notice that * as is no longer part of the import in this version.

like image 161
Doug Stevenson Avatar answered Nov 09 '22 09:11

Doug Stevenson