I need help preventing duplicate records in AngularFire when adding users to my database. How can I ensure that a user is only added once, without creating duplicates?
Here is an example of the button I am using:
<a class="btn btn-block btn-lg btn-success" href="#" ng-hide="auth.user" ng-click="auth.$login('persona')"><span><i class="fa fa-user fa-lg"></i></span> Login with <strong>Persona</strong></a>
My controller code includes:
var ref = new Firebase("https://mybase.firebaseio.com/");
$scope.auth = $firebaseSimpleLogin(ref);
var users = new Firebase("https://mybase.firebaseio.com/users");
$scope.uData = $firebase(users);
$scope.auth.$login('persona').then(function(user){
var usersArray = orderByPriorityFilter($scope.uData);
if (_.contains((_.pluck(usersArray, 'uid')),user.uid) == false){$scope.uData.$add(user)}
});
The login and redirect controllers handle user data separately, but when trying to add user data before redirection, duplicate entries are created in the database.
Any advice on addressing this issue would be greatly appreciated!