求助:Ionic v1应用Firebase密码重置功能无法正常工作
Let's work through fixing your password reset functionality step by step. Based on the code you shared, there are a few key issues likely preventing it from working as expected:
1. Mismatched Firebase SDK Method Name
Your code uses sendPasswordResetEmail(), but this is a method from Firebase SDK v3+. Since you're using the older new Firebase() syntax in your __Refs factory (Firebase SDK v2.x), the correct method name for password reset is resetPassword().
2. Incorrect Method Parameter Format
In the v2 SDK, resetPassword() expects an object containing the email field, not just a raw email string.
3. Invalid Firebase URL Placeholder
The URL https://firebasedatabase.com/ in your __Refs factory is a placeholder—you need to replace this with your actual Firebase project's database URL (found in your Firebase Console under Project Settings > General > Your apps > Firebase SDK snippet > Config).
Fixed Reset Password Controller Code
Here's the updated controller with all corrections applied:
angular.module('formulaWizard').controller('ResetPasswordCtrl', function($scope, $ionicLoading, $firebaseAuth, __Refs) { $scope.user = { email: '' }; $scope.errorMessage = null; $scope.emailSent = false; var fbAuth = $firebaseAuth(__Refs.rootRef); $scope.resetPassword = function() { $scope.errorMessage = null; $scope.emailSent = false; $ionicLoading.show({ template: 'Please wait...' }); fbAuth.resetPassword({ email: $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(); } });
Additional Critical Checks
- Enable Email/Password Auth: Ensure the Email/Password sign-in method is turned on in your Firebase Console (Authentication > Sign-in method).
- Version Compatibility: Confirm your app uses AngularFire 1.x (compatible with Firebase SDK v2.x)—newer AngularFire versions won’t work with the
new Firebase()syntax. - Test with Registered Emails: Try resetting the password for an email that’s already registered in your Firebase Auth system to rule out user-specific issues.
Let me know if you hit any snags after applying these changes!
内容的提问来源于stack exchange,提问作者Sheri Trager

