繁体   English   中英

使用Firebase检查用户身份验证

[英]Checking user authentication with Firebase

我正在使用Firebase Auth将用户登录到我的网站。 登录后,它们将重定向到/console.html。

在该文件的标题中,我有

<script type="text/javascript">
    firebase.auth().onAuthStateChanged(function(user) {
      if (user) {
        // User is signed in.
      } else {
        // No user is signed in.
        window.location.href = '/';
      }
    });
  </script>

检查它们是否已登录。如果未登录,则将它们重定向到index.html,这只是一个登录页面。 我的问题是,如果有人禁用Javascript并转至/console.html,它将被忽略,他们将能够看到该网页上显示的内容。

用于提供登录的代码使用FirebaseUI,如下所示:

  <script type="text/javascript">
    // Initialize the FirebaseUI Widget using Firebase.
    var ui = new firebaseui.auth.AuthUI(firebase.auth());

    var uiConfig = {
      callbacks: {
        signInSuccessWithAuthResult: function(authResult, redirectUrl) {
          // User successfully signed in.
          // Return type determines whether we continue the redirect automatically
          // or whether we leave that to developer to handle.
          return true;
        },
        uiShown: function() {
          // The widget is rendered.
          // Hide the loader.
          document.getElementById('loader').style.display = 'none';
        }
      },
      // Will use popup for IDP Providers sign-in flow instead of the default, redirect.
      signInFlow: 'popup',
      signInSuccessUrl: 'console.html',
      signInOptions: [
        // Leave the lines as is for the providers you want to offer your users.
        firebase.auth.EmailAuthProvider.PROVIDER_ID
      ],
      // Terms of service url.
      tosUrl: '<your-tos-url>',
      // Privacy policy url.
      privacyPolicyUrl: '<your-privacy-policy-url>'
    };

    // The start method will wait until the DOM is loaded.
    ui.start('#firebaseui-auth-container', uiConfig);
  </script>

(从Firebase文档复制)。

您绝不应该仅在客户端上保护任何重要信息,在确定页面上的内容是否安全时,请始终假定没有客户端保护。

无论您在HTML文件中显示的内容是什么,都应仅从服务器/数据库中获取/如果服务器端的某些安全规则匹配,则无论如何。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM