myApp.factory('Authentication',
['$rootScope', '$location', '$firebaseObject', '$firebaseAuth',
function($rootScope, $location, $firebaseObject, $firebaseAuth) {
var ref = firebase.database().ref();
var auth = $firebaseAuth();
var myObject;
auth.$onAuthStateChanged(function(authUser) {
if(authUser) {
var userRef = ref.child('users').child(authUser.uid);
var userObj = $firebaseObject(userRef);
$rootScope.currentUser = userObj;
} else {
$rootScope.currentUser = '';
}
});
myObject = {
login: function(user) {
auth.$signInWithEmailAndPassword(
user.email,
user.password
).then(function(user) {
$location.path('/leaderboard');
}).catch(function(error) {
$rootScope.message = error.message;
}); //signInWithEmailAndPassword
}, //login
logout: function() {
return auth.$signOut();
}, //logout
requireAuth: function() {
return auth.$requireSignIn();
}, //require Authentication
register: function(user) {
auth.$createUserWithEmailAndPassword(
user.email,
user.password
).then(function(regUser) {
var regRef = ref.child('users')
.child(regUser.uid).set({
date: firebase.database.ServerValue.TIMESTAMP,
regUser: regUser.uid,
name: user.name,
score: user.score,
email: user.email
}); //userinfo
myObject.login(user);
}).catch(function(error) {
$rootScope.message = error.message;
}); //createUserWithEmailAndPassword
}, //register
update:function(user){
var user = auth().currentUser;
user.updateProfile({
displayName: "Jane Q. User",
photoURL: "https://example.com/jane-q-user/profile.jpg"
}).then(function() {
// Update successful.
}).catch(function(error) {
// An error happened.
});
}
}; //return
return myObject;
}]); //factory
如果网址为/ team /
,则上述代码可以正常运行BUT
如果URL是/ team / john-smith /我没有被重定向?
我无法弄清楚为什么这不起作用!任何想法??
提前致谢
答案 0 :(得分:0)
将此规则与""
作为您的首要规则:
THE_REQUEST
确保使用新浏览器进行测试或完全清除浏览器缓存。