Pushing Data to Firebase under AuthID(link user and their message ? )[solved]


I’m trying to add data to firebase under user authid.Right now firebase is generating its own keys. I mean I’m trying to connect sent messages to the user who sent it.(authenticated user)

Right now db is looking like this:

enter image description here

This is how I add message. There is a model file in models folder.

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import {AngularFireAuth} from 'angularfire2/auth';
import {AngularFireDatabase,FirebaseListObservable} from 'angularfire2/database';
import {Message} from '../../models/message';

  selector: 'page-newpost',
  templateUrl: 'newpost.html'
export class NewPostPage {
  message = {} as message;

    messageRef$ : FirebaseListObservable<Item[]>;

  constructor(private fire:AngularFireAuth,private db :AngularFireDatabase,public navCtrl: NavController) {
    this.messageRef$ = this.db.list('messages');



  const promise =  this.messageRef$.push({
          message: message.message,
          //location: Number(message.location),
          .then(_ => {
              console.log('message added');
              this.message = {} as message;

          } )



This is how I generate profile:

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

  selector: 'page-fp',
  templateUrl: 'fp.html',
export class FpPage {

//profile = {} as Profile
username: string
msgnumber: number
level: number

  constructor(private fire:AngularFireAuth,private db :AngularFireDatabase,public navCtrl: NavController, public navParams: NavParams) {


this.fire.authState.take(1).subscribe(auth => {

username: this.username,
msgnumber: 0,
level: 0

}).then(() => this.navCtrl.setRoot(TabsPage));



  ionViewDidLoad() {
    console.log('ionViewDidLoad FpPage');




there is $key?: string top of model file by the way.