Sheri Trager
Sheri Trager

Reputation: 852

firebase reset password controller

Yesterday my app was launched, Ionic v1, and a few users entered the wrong password and can't log into the app. The app uses firebase authentication. I have a __refs file that points to the database and have tried numerous things trying to get the reset to work. I've tried referencing $firebaseAuth, of course my __refs, $firebase then use $firebase.auth()... I didn't write the authentication of this app so I'm not real sure how it works. I'm hoping that someone can help me.

My reset controller

angular.module('formulaWizard').controller('ResetPasswordCtrl', 

function($scope, $ionicLoading, $firebaseAuth, __Refs) { $scope.user = { email: '' }; $scope.errorMessage = null;

var fbAuth = $firebaseAuth(__Refs.rootRef);

$scope.resetPassword = function() {
  $scope.errorMessage = null;

  $ionicLoading.show({
    template: 'Please wait...'
  });

   fbAuth.sendPasswordResetEmail($scope.user.email)
      .then(showConfirmation)
      .catch(handleError);
};


function showConfirmation() {
  $scope.emailSent = true;
  $ionicLoading.hide();
}

function handleError(error) {
  switch (error.code) {
    case 'INVALID_EMAIL':
    case 'INVALID_USER':
      $scope.errorMessage = 'Invalid email';
      break;
    default:
      $scope.errorMessage = 'Error: [' + error.code + ']';
  }

  $ionicLoading.hide();
}
});

My Refs file

angular.module('formulaWizard')
 .factory('__Refs', function ($firebaseArray, $firebaseObject) {
// Might use a resource here that returns a JSON arrayf
var ref = new Firebase('https://firebasedatabase.com/');
 return {
    rootRef: ref,
    customers: ref.child('customers'),

}
});

Upvotes: 0

Views: 439

Answers (1)

Sheri Trager
Sheri Trager

Reputation: 852

I can't take credit for the answer it was provide by Abimbola Idowu on HackHands.
Since I paid for the answer I thought I would share it with anyone else that might also be stumped by this.

$scope.resetPassword = function() {
  $scope.errorMessage = null;

  $ionicLoading.show({
    template: 'Please wait...'
  });

   __Refs.rootRef.resetPassword({ email: $scope.user.email }, function(error) {
    if (error === null) {
      showConfirmation();
    } else {
      handleError()
    }
  });
};

This is the __refs service

angular.module('formulaWizard')
.factory('__Refs', function ($firebaseArray, $firebaseObject) {
// Might use a resource here that returns a JSON arrayf
var ref = new Firebase('https://firebasedatabase.com/');
  return {
    rootRef: ref,

  }
});

Upvotes: 1

Related Questions