Firebase+ionic problems

HI, I am a norwegian programmer and designer, just starting using ionic, came from framework7. However, now I am having problems.

I have a modified version of this: http://market.ionic.io/starters/business-directory-firebase-admin---admin-ui-for-firebase-backend

But what I want it to do, is for the signed in users to only see there businesses and not all the others. I have had no luck and I am on my third day trying to figure this out. Tried editing rules in firebase, no go, tried adding uid to the ng-repeat="item in vm.items"
even tried to do it in JS, but I think there is something I am missing here…

All other changes I have gotten to work, but that one I can’t figure out.

So could anyone please help :smiley:

Thanks

Hi, can you provide some code and database structure ?

Thanks for your reply, here is the firebase screen…

Businesses html:

<ion-nav-buttons side="right">
	<button class="button button-clear icon ion-plus" ng-click="vm.addItem()"></button>
</ion-nav-buttons>

<ion-content has-header="true" ng-init="vm.search = ''">

	<div class="item search-box">
		<input type="text" placeholder="Search" ng-model="vm.search" />
	</div>

	<ion-list can-swipe="true" ng-if="vm.items.length > 0">
		<ion-item ng-repeat="item in vm.items  | filter: { name: vm.search } | orderBy:'uid':true"  class="item-text-wrap" ng-click="vm.openDetails(item)">
			<h2>{{item.name}}</h2>
			<h3>{{item.categoryName}}</h3>

			<p>{{item.description | limitTo: 240 }}{{item.body.length > 240 ? '...' : ''}}</p>

			<ion-option-button class="button-assertive" ng-click="vm.deleteItem(item)">
				Delete
			</ion-option-button>

			<ion-option-button class="button-positive" ng-click="vm.updateItem(item)">
				Edit
			</ion-option-button>
		</ion-item>
	</ion-list>
	
</ion-content>

Businesses.controller.js
(function() {
‘use strict’;

angular
	.module('bizdir-frb-admin.businesses')
	.controller('BusinessesController', BusinessesController);

BusinessesController.$inject = ['businessesService', '$ionicListDelegate', 'editBusinessService', '$state'];

/* @ngInject */
function BusinessesController(businessesService, $ionicListDelegate, editBusinessService, $state) {
	var vm = angular.extend(this, {
		items: [],
		addItem: addItem,
		deleteItem: deleteItem,
		updateItem: updateItem,
		openDetails: openDetails
	});

	(function activate() {
		selectAll();
	})();

	// ********************************************************************

	function openDetails(item) {
		$state.go('app.business', {
			id: item.$id,
			
		});
	}

	function deleteItem(item) {
		businessesService.deleteItem(item);
		selectAll();
	}

	function updateItem(item) {
		$ionicListDelegate.closeOptionButtons();

		editBusinessService.show(item.name, item.description).then(function(result) {
			if (result.canceled) {
				return;
			}

			businessesService.saveItem(item.$id, {
				name: result.name,
				description: result.description
			});
		});
	}

	function selectAll() {
		businessesService.selectAll().then(function(items) {
			vm.items = items;
		});
	}

	function addItem() {
		editBusinessService.show().then(function(result) {
			if (result.canceled) {
				return;
			}

			var item = {
				name: result.name,
				description: result.description
			};

			businessesService.insert(item)
				.then(function() {
					selectAll();
				});
		});
	}
}

})();

Method selectAll() returns all items from business for every user.

You have UID inside business table and you can use it to compare with logged in user ID. If auth user ID equals to business UID than you can call a service to retrieve data with that ID.

Here you can find example how to write firebase query for service (pay attention on equalsTo):
https://firebase.google.com/docs/reference/js/firebase.database.Query

Update

Example:

  // Auth user is LvlbC1ohiDeUVIlG950YyYuqTPo1:

  var authuserid = LvlbC1ohiDeUVIlG950YyYuqTPo1;

  var ref = firebase.database().ref("businesses");
  var query = ref.orderByChild("name").equalTo(authuserid).on("child_added", function(snapshot){
    console.log(snapshot.val());
  });

Ohh lord, did not even see that, Thank you very much…