我想知道如何将页面配置为只允许在Firebase中通过身份验证的用户。我在设置我的网站时遇到了困难,我希望用户输入登录名和密码,并且在认证之后,将被定向到他的个人资料。只允许通过身份验证的用户在页面上
配置文件(网页),该用户被导向,具有URL
www.example.com/"user.uid"/index.html
但这页面只能针对谁被认证的用户才能访问,所以如果有人访问URL
www.example.com/"user.uid"/index.html
必须将用户定向到主页
登录页面上的代码:
btnLogin.addEventListener('click', e =>{
const email = txtEmail.value;
const pass = txtPassword.value;
const auth = firebase.auth();
const promise = auth.signInWithEmailAndPassword(email,pass);
promise
.then(user => window.location.href="http://www.example.com/" + user.uid + "/index.html")
.catch(e => console.log(e.message));
})
客户端页面上的代码:
firebase.auth().onAuthStateChanged(firebaseUser => {
if(firebaseUser){
console.log(firebaseUser);
}else{
window.location.href = "http://www.example.com";
console.log("offline");
}
});
我遇到的问题是,当您重定向到客户端页面时,用户的状态变为脱机状态