问题描述
假设我已将我的写入规则配置为特定的 email
:
Lets say I've configured my write rules to a specific email
:
{
"rules": {
".read": true,
".write": "auth.email == '[email protected]'"
}
}
然后我使用 angularFireAuth
服务登录:
And I login in using the angularFireAuth
service:
.controller('loginCtrl', ["$scope", "$rootScope", "angularFireAuth", function($scope, $rootScope, angularFireAuth) {
var ref = new Firebase("https://test.firebaseio.com/");
angularFireAuth.initialize(ref, {scope: $scope, name: "user"});
$scope.cred = {};
$scope.signin = function() {
angularFireAuth.login('password', {
email: $scope.cred.user,
password: $scope.cred.password,
rememberMe: true
});
}
}]);
我有一个 newCtrl
用于向我的收藏中添加新项目:
I have a newCtrl
that I use to add new items to my collection:
.controller('newCtrl', ["$scope", "$rootScope", "angularFireCollection", function($scope, $rootScope, angularFireCollection) {
var ref = new Firebase("https://test.firebaseio.com/");
$scope.items = angularFireCollection(ref);
}]);
当我在视图中调用 items.add()
时:
When I invoke items.add()
in my view:
<input type="text" ng-model="item.name" />
<input type="text" ng-model="item.desc" />
<button ng-click="items.add(item)">submit</button>
即使在通过 loginCtrl
- 如何在登录后在整个应用程序中创建持久身份验证状态?
- 如何在注销后删除整个应用程序中的持久身份验证状态?
- How do I create a persistent authentication state across my entire application after logging in?
- How do I remove a persistent authentication state across my entire application after logging out?
推荐答案
您的身份验证状态是基于会话的,不依赖于您的控制器范围,因此您的应用程序中已经有了持久身份验证状态".
Your authentication state is session-based, not dependent on your controller scope, so you already have a "persistent authentication state" across your application.
您的代码肯定有其他原因导致了该错误,但就您的问题而言,您可以看到一个工作示例 此处 使用 [email protected]
作为电子邮件和 example
作为密码.
There must be something else going on with your code that is generating that error, but as far as your question goes, you can see a working example here using [email protected]
as the email and example
as the password.
我也匹配了您的安全规则,因此如果您以 [email protected]
的身份登录,密码为 test
,您将无法创建 项目
.
I matched your security rules as well, so if you login instead as [email protected]
with password test
you won't be able to create items
.
这篇关于持久身份验证状态 Firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!