Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49134

Create a User Profile Page FireBase

$
0
0

@iconio wrote:

Hey guys! I’m new on ionic and Firebase and I’m having a big error.

I’m creating a E-mail and Password login using Firebase as database, the login is fine, it works like it’s supposed to.

What I want is to direct the user to a Profile Page, on which will have a Username, First Name and Last Name to be entered by the user. The problem is… there is no way I can write the profile on the database, has anybody experienced something like that?

You will see on the “ionViewWillLoad” that I have been trying to get the user UID. In order for me to test it, I’ve been trying to get the user email. I can console.log the email but when I try to return it, I get [object Object]. What am I doing wrong?

Here is my code:

import { Profile } from '../../models/profile';
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFireDatabase } from 'angularfire2/database';
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

@IonicPage()
@Component({
  selector: 'page-profile',
  templateUrl: 'profile.html',
})
export class ProfilePage {

  profile = {} as Profile;

  constructor(private afAuth: AngularFireAuth, private afDatabase: AngularFireDatabase,
              public navCtrl: NavController, public navParams: NavParams) {
  }

  ionViewWillLoad() {
    this.afAuth.authState.subscribe(auth => console.log(auth.email));
    let v = this.afAuth.authState.subscribe(auth => {return auth.email} );
    console.log("The email " + v);
  }

  createProfile() {
    this.afAuth.authState.take(1).subscribe(auth => {
          this.afDatabase.object("profile/${auth.uid}").set(this.profile)
            .then(() => this.navCtrl.setRoot('MainPage'));
    })
  }
}

Thank you sooo much!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49134

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>