【发布时间】:2019-01-25 12:48:31
【问题描述】:
我正在使用 Firebase 身份验证将用户登录到我的网站。登录后,它们会被重定向到 /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 文档复制)。
【问题讨论】:
标签: javascript html firebase firebase-authentication