[英]FirebaseUi-Auth mandatory login
I am trying to implement mandatory login for my website. 我正在尝试为我的网站实施强制登录。 The problem I am having is that I can't find a way to do so. 我遇到的问题是我找不到办法。 Let's say I create a SignIn page like... 假设我创建了一个像...这样的SignIn页面
var uiConfig = {
signInSuccessUrl: '<url-to-redirect-to-on-success>',
signInOptions: [
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
firebase.auth.FacebookAuthProvider.PROVIDER_ID,
firebase.auth.TwitterAuthProvider.PROVIDER_ID,
firebase.auth.GithubAuthProvider.PROVIDER_ID,
firebase.auth.EmailAuthProvider.PROVIDER_ID,
firebase.auth.PhoneAuthProvider.PROVIDER_ID
],
tosUrl: '<your-tos-url>'
};
var ui = new firebaseui.auth.AuthUI(firebase.auth());
ui.start('#firebaseui-auth-container', uiConfig);
</script>
..on a page called www.example.com/SignIn ..在一个名为www.example.com/SignIn的页面上
If I go to www.example.com/Index 如果我去www.example.com/Index
I could totally bypass all the signin. 我可以完全绕过所有的登录。
I figured that something like this 我认为这样的事情
if ( FirebaseUser.getCurrentUser () != null ) {
redirect to sign in page } 重定向到登录页面}
How ? 怎么样 ?
Thanks 谢谢
Use onAuthStateChanged
listener on the www.example.com/Index
page: 在www.example.com/Index
页面上使用onAuthStateChanged
侦听器:
firebase.auth().onAuthStateChanged(function(user) {
if (!user) {
window.location.assign('www.example.com/SignIn');
}
...
});
However, this is not the right way to enforce access control. 但是,这不是实施访问控制的正确方法。 You should enforce signed in access via either mechanism: 您应该通过以下任一机制强制执行登录访问:
Also you can use session cookies to do so, depending on your site architecture. 您也可以使用会话cookie来执行此操作,具体取决于您的站点体系结构。 Firebase now, also provides the ability to mint longer term session cookies Firebase现在也提供了制作长期会话cookie的能力
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.