I’m having problems with a Firebase vs Ionic 3 app when I create a new user in the app, I don’t know why I can create a new user only once every day and I try again in the same day but the database doesn’t update. It seems nonsense but that’s exactly waht’s happening. I have a Firebase file called firebase.ts
with the database credentials to create the connection:
export const firebaseConfig = {
// I replaced the data with "#" here for security reasons:
apiKey: "###",
authDomain: "###",
databaseURL: "###",
projectId: "###",
storageBucket: "###",
messagingSenderId: "###",
appId: "###"
}
Then I have the register function in login.ts
file:
createAccount() {
let load = this.loadingCtrl.create();
load.present();
this.authProvider.register(this.registerForm)
.then((res) => {
let uid = res.user.uid;
//organize data
let data = {
uid: uid,
name: this.registerForm.name,
email: this.registerForm.email
};
//Gravar usuario no firestore
this.firebaseProvider.postUser(data)
.then(() => {
this.storage.set('usuario', data)
.then(() => {
load.dismiss();
this.navCtrl.setRoot('HomePage');
})
})
.catch((err) => {
load.dismiss();
})
})
.catch((err) => {
load.dismiss();
})
}
And the providers settings in firebase.ts
from folder Providers :
import { Injectable } from "@angular/core";
import { AngularFirestore } from "angularfire2/firestore";
import "rxjs/add/operator/map";
@Injectable()
export class FirebaseProvider {
constructor(private afs: AngularFirestore) {}
//Save user on firestore
saveUser = data =>
this.afs
.collection("Users")
.doc(data.$key)
.update(data);
//Create user on firestore
postUser = data =>
this.afs
.collection("Users")
.doc(data.uid)
.set(data);
getUser(uid){
return this.afs.firestore.collection('Users').doc(uid)
.get();
}
}
And finally authentication.ts
file also in Providers folder:
import { Injectable } from '@angular/core';
import { AngularFireAuth } from "angularfire2/auth";
@Injectable()
export class AuthProvider {
constructor(
private afAuth: AngularFireAuth
) {
}
//Create new user
register = (data) => this.afAuth.auth.createUserWithEmailAndPassword(data.email, data.password);
//Login for existing user
login = (data) => this.afAuth.auth.signInWithEmailAndPassword(data.email, data.password);
}
What could I do? Literally when I create one user, the first from the day, everything is fine but then the next time I try it, the database doesn’t update! Any help?