问题描述
限时送ChatGPT账号..我正在使用 $firebaseSimpleLogin 使用电子邮件/密码登录 Firebase.
I am using $firebaseSimpleLogin to log into Firebase using email/password.
当我使用电子邮件/密码登录时效果很好,我可以看到 sessionkey 被自动保存为 cookie.
It is working rather well when I log in using email/password, I could see sessionkey being saved automatically as a cookie.
但是,要记住登录,以便用户只需登录一次.所以我在认证过程中包含了 {rememberMe: true}.
However, would like to remember the log in such that user only have to log in once. So I included {rememberMe: true} during auth.
如何在页面开始加载时检查会话是否还处于活动状态?
How do I check if the session is still alive at the beginning of the page being loaded?
推荐答案
根据您的问题,我假设您正在使用 Angular JS.
From your question, I assume you're using Angular JS.
您可以在主模块上执行 run
块,每次加载页面时都会运行该块.我对 Angularfire 不太了解,这是我在黑客日项目中使用的代码,用于检查身份验证并在需要时重定向到登录页面.
You can execute a run
block on your main module, which is run everytime the page is loaded. I don't know much about Angularfire, this is the code I'm using on a hack day project to check auth and redirect to the login page if needed.
FirebaseRef
是指向我的 Firebase 实例的包装器.
FirebaseRef
is a wrapper that points to my Firebase instance.
这也确保 currentUser
对象在所有范围内都可用.
This also makes sure that the currentUser
object is available in all scopes.
var minib = angular.module('minib', ['ngRoute', 'firebase']);
minib.run(function($rootScope, $location, $firebaseSimpleLogin, firebaseRef) {
$rootScope.auth = $firebaseSimpleLogin(firebaseRef());
$rootScope.auth.$getCurrentUser().then(function(user) {
if (user) {
$rootScope.currentUser = user;
} else {
$location.path('/login');
}
});
});
这篇关于$firebaseSimpleLogin 和无需重新登录的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论