LoginPage.html
<div layout="column" ng-app="HelpingHand" ng-controller="login" layout-
fill>
<md-content>
< div layout="column" >
<md-input-container class="md-block">
<input ng-model="email" type="email" placeholder="Email (required)"
ng-required="true">
</md-input-container>
<md-input-container class="md-icon-float md-block">
<label>Password</label>
<input ng-model="password" type="text">
</md-input-container>
<md-button ng-href="login.html" ng-click="emaillogin()" class="md-
raised md-warn">Login</md-button>
<md-button class="md-raised md-primary">Cancel</md-button>
</div>
Login.js
var app = angular.module('HelpingHand', ['ngMaterial','ngMessages']);
app.controller('login', function($scope) {
$scope.emaillogin = function(){
firebase.auth().signInWithEmailAndPassword($scope.email,
$scope.password).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
});
}
});
错误消息返回以下错误 - 发生网络错误(例如超时,中断连接或无法访问的主机)。
错误代码返回以下错误 - auth / network-request-failed
我对此代码的错误是什么?
答案 0 :(得分:0)
对我来说,问题是我在使用windows.location = "url"
收到回复之前尝试从页面导航。
这似乎是回应的时间问题。这个违规问题在if(true)
声明中有说明。
function toggleSignIn() {
if (firebase.auth().currentUser) {
// [START signout]
firebase.auth().signOut();
// [END signout]
} else {
var email = document.getElementById('email').value;
var password = document.getElementById('password').value;
if (email.length < 4) {
alert('Please enter an email address.');
return;
}
if (password.length < 4) {
alert('Please enter a password.');
return;
}
// Sign in with email and pass.
// [START authwithemail]
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// [START_EXCLUDE]
if (errorCode === 'auth/wrong-password') {
alert('Wrong password.');
} else {
alert(errorMessage);
}
console.log(error);
document.getElementById('quickstart-sign-in').disabled = false;
// [END_EXCLUDE]
});
// [END authwithemail]
// clear user / pass
document.getElementById('email').value = "";
document.getElementById('password').value = "";
/*
if (true) {
window.location = "{URL}";
}
*/
}
document.getElementById('quickstart-sign-in').disabled = true;
}
答案 1 :(得分:-1)
解决了问题..只是弄乱了我的项目ID