我是ionic
1.x和firebase
的新手,尝试应用onAuthStateChanged
方法来跟踪当前记录的用户和身份验证更改。我可以使用电子邮件和密码注册新用户,能够登录和注销,但在实施onAuthStateChanged
时遇到了麻烦。
这是我的services.js
文件:
angular.module('app.services', [])
.service("fireBaseService", function(){
//sign up
this.signUp = function(userEmail, password){
...
}
//sign in
this.signIn = function(userEmail, password){
...
}
this.signOut = function(){
....
})
.service("authObserver", function(){
this.auth = firebase.auth().onAuthStateChanged(function(user) {
if (user) {
console.log("is logged in");
} else {
console.log("signed out!");
// No user is signed in.
}
});
});
有什么想法吗?