Advertisement
Guest User

Untitled

a guest
Apr 27th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. createUserWithEmailAndPasswordAsAdmin(
  2. email: string,
  3. displayName: string,
  4. password: string) {
  5.  
  6. /*
  7. The createUserWithEmailAndPassword() function signs
  8. the user automaticly in, so we have to create a secondary app to create users,
  9. because we want to stay signed in as Admin.
  10. */
  11.  
  12. const secondaryApp = firebase.initializeApp(environment.admin, 'admin');
  13.  
  14. return secondaryApp.auth()
  15. .createUserWithEmailAndPassword(email, password)
  16. .then((credential) => {
  17. this.setUserData(credential.user, displayName);
  18. secondaryApp.auth().signOut();
  19. secondaryApp.delete()
  20. .then(function () {
  21. console.log('App deleted successfully');
  22. })
  23. .catch(function (error) {
  24. console.log('Error deleting app:', error);
  25. });
  26. });
  27. }
  28.  
  29. private setUserData(user, displayName) {
  30. let classRef: DocumentReference = null;
  31.  
  32. const userRef: AngularFirestoreDocument<any> = this.afs.doc(`users/${user.uid}`);
  33. const data: User = {
  34. uid: user.uid,
  35. email: user.email || null,
  36. displayName: displayName,
  37. photoURL: user.photoURL || '..',
  38.  
  39. return userRef.set(data);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement