【发布时间】:2017-03-07 20:50:54
【问题描述】:
我目前正在开发一个使用 AngularJS 使用 Firebase 日志系统制作的应用程序。当我尝试登录时,我有一个奇怪的重定向 - 无论登录是否成功,它都会出于某种原因重定向到注册页面。如果警报应该出现,它会显示在注册页面上。 尝试删除注册页面的路线 - 没有运气。尝试删除触发 OnAuthStateChanged 时发生的操作 - 仍然重定向。尝试调试应用程序-似乎该功能
for (var i = 0; i < eventFnsLength; i++) {
if (!event.isImmediatePropagationStopped()) {
handlerWrapper(element, event, eventFns[i]);
}
}
在第 3532 行的 angular.js 中导致了这种情况,但我不知道如何让它停止。
SignInCtrl.js
angular.module('szybkiePisanie')
.controller('SignInCtrl', ["$scope", "$firebaseAuth", function ($scope, $firebaseAuth) {
$scope.SignIn = function (event) {
if ($scope.user.email != undefined) var email = $scope.user.email; else { alert("Wpisz adres e-mail"); return; }
if ($scope.user.password != undefined) var password = $scope.user.password; else { alert("Wpisz hasło"); return; }
firebase.auth().signInWithEmailAndPassword(email, password).catch(function (error) {
var errorCode = error.code;
var errorMessage = error.message;
if (email.length < 4) {
alert('Proszę wpisać adres email.');
return;
}
if (password.length < 4) {
alert('Proszę wpisać hasło.');
return;
}
;
if (errorCode === 'auth/wrong-password') {
alert('Błędne hasło.');
}
else if (errorCode === 'auth/invalid-email') {
alert('Nieprawidłowy adres email');
}
else if (errorCode === 'auth/user-disabled') {
alert('Użytkownik zablokowany');
}
else if (errorCode) {
alert(errorMessage);
}
})
}
}]);
注册Ctrl.js
angular.module('szybkiePisanie')
.controller('RegisterCtrl', ["$scope", "$firebaseAuth", function ($scope, $firebaseAuth) {
$scope.Register = function (event) {
if ($scope.user.email != undefined) var email = $scope.user.email; else { alert("Wpisz mejl"); return; }
if ($scope.user.password != undefined) var password = $scope.user.password; else { alert("Wpisz haslo"); return; }
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function (error) {
var errorCode = error.code;
var errorMessage = error.message;
if (email.length < 4) {
alert('Please enter an email address.');
return;
}
if (password.length < 4) {
alert('Please enter a password.');
return;
}
})
}
}]);
script.js(路由)
angular.module('szybkiePisanie', ['ngRoute', 'firebase'])
.config(['$routeProvider',
function ($routeProvider) {
$routeProvider
.when('/home', {
templateUrl: 'Home/home.html',
controller: 'HomeCtrl'
})
.when('/practice', {
templateUrl: 'Practice/practice.html',
controller: 'PracticeCtrl'
})
.when('/signin', {
templateUrl: 'SignIn/signin.html',
controller: 'SignInCtrl'
})
.when('/profile', {
templateUrl: 'Profile/profile.html',
controller: 'ProfileCtrl'
})
.when('/register', {
templateUrl: 'Register/register.html',
controller: 'RegisterCtrl'
})
.otherwise({
redirectTo: '/home'
})
}]);
编辑: 重定向不仅是由 Singing in 引起的。事实上,任何按钮或下拉菜单都会导致我的应用程序从“/singin”重定向到“/register”。奇怪。
【问题讨论】:
-
你能提供一个小提琴来让我们重现这个吗?
-
我无法重现任何重定向。由于我没有任何有效的电子邮件通行证,我尝试了一封带有任何密码文本的有效电子邮件,但我只收到一个导致 400 错误的请求,因为身份验证失败。但我没有看到任何重定向
标签: javascript angularjs firebase firebase-authentication