Skip to content

Instantly share code, notes, and snippets.

@feliperfranco
Created November 21, 2017 21:38
Show Gist options
  • Save feliperfranco/ef0a997a7faa6b5fcd4b9a6f57994f1a to your computer and use it in GitHub Desktop.
Save feliperfranco/ef0a997a7faa6b5fcd4b9a6f57994f1a to your computer and use it in GitHub Desktop.
Example of save another data to a user with Firebase
import { AngularFireDatabase } from 'angularfire2/database';
import { Injectable } from '@angular/core';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
@Injectable()
export class AccountProvider {
private PATH = 'usuarios/';
constructor(public auth: AngularFireAuth, private db: AngularFireDatabase) { }
public createAccount(user: any) {
return new Promise((resolve, reject) => {
this.auth.auth.createUserWithEmailAndPassword(user.email, user.password)
.then((firebaseUser: firebase.User) => {
this.db.object(this.PATH + firebaseUser.uid).set({ cpf: 'aqui vai o cpf', rg: '' });
// Aqui eu salvo o nome pois posso acessar mais facilmente com o AngularFireAuth
firebaseUser.updateProfile({ displayName: user.name, photoURL: null });
resolve();
})
.catch(e => {
reject(e);
});
});
}
getUserName() {
return this.auth.auth.currentUser.displayName;
}
getOtherUserValues() {
return this.db.object(this.PATH + this.auth.auth.currentUser.uid)
.snapshotChanges()
.map(changes => {
return { key: changes.key, ...changes.payload.val() };
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment