来自Simple Web Login文档,它声称您可以通过执行以下操作恢复 session :
var auth = new FirebaseSimpleLogin(chatRef, function(error, user) {
...
});
是否有 AngularFire 的等效项?
$firebaseSimpleLogin
构造函数将 firebase 引用作为其唯一参数..
具体来说,我想要做的是匿名登录一次并在刷新整个页面时恢复登录。这可以实现吗?
最佳答案
是否保留您的身份验证 session 取决于您传递给登录方法的参数。无论您使用 FirebaseSimpleLogin 还是 $firebaseSimpleLogin 在这里都无关紧要。
var auth = $firebaseSimpleLogin(ref);
$rootScope.$on('$firebaseSimpleLogin:login', function(user) {
console.log('logged in', user.uid);
});
// automagically logs in the next time you call $firebaseSimpleLogin() after page refresh
auth.$login('anonymous', { rememberMe: true });
// does not automagically log in
auth.$login('anonymous');
更新从 Angular 1.x 和 Firebase 2.x 开始,此语法和行为已更改。
来自 Firebase 文档中的 remember
属性:
If not specified - or set to
default
- sessions are persisted for as long as you have configured in the Login & Auth tab of your App Dashboard. To limit persistence to the lifetime of the current window, set this tosessionOnly
. A value ofnone
will not persist authentication data at all and will end authentication as soon as the page is closed.
var auth = $firebaseAuth(ref);
$firebaseAuth.$onAuth(function(user) {
console.log('logged ' + (user? 'in' : 'out'), user && user.uid);
});
// stays logged in for length specified in the app dashboard
auth.$authAnonymously();
// stays logged in until the browser closes
auth.$authAnonymously({ remember: 'sessionOnly' });
// does not stay logged in on page refresh
auth.$authAnonymously({ remember: 'none' });
关于javascript - AngularFire:恢复匿名 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22774871/