Ionic 4没有创建Firebase应用程序错误显示

时间:2019-05-29 12:53:27

标签: firebase ionic-framework ionic4

我正在关注一些有关离子Firebase身份验证的教程。我将其与Firebase连接时显示错误。

[DEFAULT]:Firebase:未创建Firebase应用程序'[DEFAULT]'-调用Firebase App.initializeApp()(app / no-app)。

任何人都可以告诉我firebase项目中的代码是否有问题或我在做一些错误?已经尝试在evironment.ts中导入firebaseconfig,显示同样的错误。谢谢

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';

import { environment } from 'src/environments/environment';
import { AuthenticateService } from 
 './services/authentication.service';
import { AngularFireAuthModule } from '@angular/fire/auth';
import { AngularFireModule } from '@angular/fire';


@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
  BrowserModule,
  IonicModule.forRoot(),
  AppRoutingModule,
  AngularFireModule.initializeApp({

   apiKey: "AIzaSyCNWMCYbX88_UKcuk_IZgeaoRphwtLlXzY",
   authDomain: "freshfarmfood-8a564.firebaseapp.com",
   databaseURL: "https://freshfarmfood-8a564.firebaseio.com",
   projectId: "freshfarmfood-8a564",
   storageBucket: "freshfarmfood-8a564.appspot.com",
   messagingSenderId: "368787448857",
   appId: "1:368787448857:web:ab7f56971ae08874"
}),
AngularFireAuthModule

],
 providers: [
   StatusBar,
   SplashScreen,
    AuthenticateService,

{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
 ],
 bootstrap: [AppComponent] . 
})
export class AppModule {}

服务

import { Injectable } from "@angular/core";
import * as firebase from 'firebase/app';

@Injectable()
export class AuthenticateService {

constructor(){}

registerUser(value){
 return new Promise<any>((resolve, reject) => {
 firebase.auth().createUserWithEmailAndPassword(value.email, 
value.password)
 .then(
   res => resolve(res),
   err => reject(err))
 })
}

loginUser(value){
  return new Promise<any>((resolve, reject) => {
  firebase.auth().signInWithEmailAndPassword(value.email, 
 value.password)
 .then(
   res => resolve(res),
   err => reject(err))
 })
 }

logoutUser(){
  return new Promise((resolve, reject) => {
   if(firebase.auth().currentUser){
     firebase.auth().signOut()
    .then(() => {
      console.log("LOG Out");
      resolve();
     }).catch((error) => {
       reject();
     });
    }
  })
}

userDetails(){
 return firebase.auth().currentUser;
  } 
}

register.ts

import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators, FormControl } from 
'@angular/forms';
import { AuthenticateService } 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: AuthenticateService,
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.navigateBack('');
}


}

0 个答案:

没有答案