2014-12-24 3 views
0
app.factory("Auth", ["$firebaseAuth", function($firebaseAuth) { 
    var ref = new Firebase("https://XXXXXX.firebaseio.com/"); 
    var auth = $firebaseAuth(ref); 

    var Auth = { 
    login: function(){ 
     return auth.$authWithPassword({ 
     "email": "[email protected]", //hard-coding in the email & password for testing 
     "password": "1" 
     }, function(error, authData) { 
     if (error) { 
      console.log("Login Failed!", error); 
     } else { 
      console.log("Login Success!", authData); 
     } 
     }); 
    } 
    return Auth; 
}]); 

app.controller("SampleCtrl", ["$scope", "Auth", "$firebaseAuth", function($scope, Auth, $firebaseAuth) { 
    $scope.login = Auth.login(); 
}]); 

나는 angularFire 사용자 인증 기능이 오류를 반환AngularFire authWithPassword는

<button ng-click="login()">Login</button> 

를 사용하는 공장을 만들려고하고 각 공장 작동하지? PLUNKER

+0

Plunkr에서 이것을 재현 할 수 있습니까? –

+0

도와주세요 http://plnkr.co/edit/8fNus4oiqEFmMXNjq6D1?p=preview – user2901633

답변

0
app.controller("loginCtrl", ["$scope", "Auth", function($scope, Auth){ 
    $scope.login = function(){ 
    Auth.login().then(function(){ 
     console.log("OK"); 
    }); 
    }; 
}]); 

는 어떻게 든이 그것을 다음 함수 내에서 Auth.login()then 포장하여 작동합니다. 아무도 왜 작동하는지 설명 할 수 있습니까?

AngularFire를 사용하는 경우 다음과 같이 전화가 보일 것입니다 암호 제공자로 로그인 할 수
0

나를 위해 작동이 시도 :

angular.module('database-operations').factory('Auth', ["$firebaseAuth", function($firebaseAuth) { 
     var ref = new Firebase("https://XXXXX.firebaseio.com/"); 
     var auth = $firebaseAuth(ref); 

    return{ 
      login: function(){ 
       return auth.$authWithPassword({ 
        "email": "[email protected]", //hard-coding in the email & password for testing 
        "password": "1" 
       }).then(function(authData){ 
        console.log('Login successful',authData.uid); 
       }).catch(function(error) { 
        console.error("Authentication failed:", error); 
       }); 
      } 

     } 
    } 
    ]); 
+0

정확한 문제가 무엇인지 확실하지 않은 경우 성공 메시지와 오류가 기록됩니다. – user2901633

1

: 당신이 AngularFire을 사용하지 않는 경우

var ref = new Firebase("url","name"); 
    var svcAuth = return $firebaseAuth(ref); 
    svcAuth.$authWithPassword({ 
         email: email, 
         password: "******"}) 
         .then(onLogon) 
         .catch(onError); 

    function onLogon(authData) { 
      console.log("Authenticated payload:", authData);     
    } 

    function onError(error) { 
      console.log("Authentication error:", error); 
    } 

은 (Firebase.js 만 사용)에 로그인하는 코드가 표시되어야합니다

var ref = new Firebase("url"); 
ref.authWithPassword({ 
    email : "email", 
    password : "*****" 
}, function(error, authData) { 
    if (error) { 
    console.log("Login Failed!", error); 
    } else { 
    console.log("Authenticated payload:", authData); 
    } 
}); 

희망이 있습니다.