【发布时间】:2016-04-13 03:48:26
【问题描述】:
我刚开始 angularfire Auth!我在登录时遇到了这个问题,如果你们对如何制作电子邮件注册表有任何建议,我会很高兴听到这个消息。这是我收到的错误:
错误:Firebase.authWithPassword 失败:第一个参数必须是有效对象。
这是我的 script.js:
var app = angular.module('LoginApp', ["firebase"])
app.controller('AuthCtrl', [
'$scope', '$rootScope', '$firebaseAuth', function($scope, $rootScope, $firebaseAuth) {
var ref = new Firebase('https://uniquecoders.firebaseio.com/')
$scope.auth = $firebaseAuth(ref);
$scope.signIn = function(){
var ref = new Firebase('https://uniquecoders.firebaseio.com/')
ref.authWithPassword('email', {
email: $scope.signInEmail,
password: $scope.signInPassword
}, function(error,userData){
if(error = 'INVALID_EMAIL'){
alert("The Email you entered is Invalid")
}
else if(error = 'INVALID_PASSWORD'){
alert("The Password you entered is Invalid")
}
else{
console.log(error)
}
})
}
}]
);
还有我们的Index.html:
<!DOCTYPE html>
<html lang="en-US">
<head>
<script src="jquery.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js"></script>
<script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/1.1.3/angularfire.min.js"></script>
<script src="https://cdn.firebase.com/js/simple-login/1.6.2/firebase-simple-login.js"></script>
<script src = "http://s.codepen.io/assets/libs/modernizr.js"></script>
<script type="text/javascript" src="script.js"></script>
<meta charset="UTF-8">
<meta name="X-UA-Compatible" content="">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="keywords" content="">
<meta name="description" content="">
<title>Login - UniqueCoders</title>
<link rel="icon" href="favicon.ico">
<link rel="stylesheet" href="main.css">
</head>
<body ng-app="LoginApp">
<div id="page">
<header class="container">
<div class="row">
<img src="https://lh5.googleusercontent.com/-UXr_le-DEc4/VogTLE2yDfI/AAAAAAAAAfI/9RycRDVGNu8/w993-h207-no/uniquecoders.png" alt="UniqueCoders">
</div>
</header>
<main class="container">
<div class="row login">
<form ng-controller="AuthCtrl">
<input type="email" name="email" placeholder="Email" ng-model = "signInemail" id="email">
<input type="password" name="password" ng-model = "signInpassword" placeholder="Password" id="password">
<input type="submit" value="Login" ng-click = "signIn()">
</form>
</div>
</main>
<footer class="container">
<div class="row">
<small>© 2016. Unique Coders</small>
</div>
</footer>
</div>
<!-- Scripts at the end for faster loading -->
</body>
</html>
【问题讨论】:
-
去掉第一个参数:
ref.authWithPassword('email',.
标签: angularjs authentication firebase-authentication