所以我正在进一步开发这个网站,这次我添加了一个 firebase 登录,一旦你登录,它应该将你重定向到主页。但是,对于每个 window.location 方法,我都会收到“此站点无法提供安全连接,它发送了无效响应”。一旦我注释掉那条线,一切都很好。我浏览了所有与 stackoverflow 相关的问题和 js 文档,似乎找不到答案,所以任何帮助都会很受欢迎。
var firebaseConfig = {
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
const auth = firebase.auth();
//Get Elements
const txtEmail = document.getElementById('txtEmail');
const txtPassword = document.getElementById('txtPassword');
const btnLogin = document.getElementById('btnLogin');
const btnSignUp = document.getElementById('btnSignUp');
const btnLogOut = document.getElementById('btnLogOut');
btnLogOut.style.display= 'none'
//Add login event
btnLogin.addEventListener('click', e => {
event.preventDefault()
const email = txtEmail.value;
const pass = txtPassword.value;
//Sign In
try {
auth.signInWithEmailAndPassword(email, pass);
} catch (error) {
console.log(error.message);
}
})
//Add SignUp Event
btnSignUp.addEventListener('click', e => {
const email = txtEmail.value;
const pass = txtPassword.value;
//Sign up
try {
auth.createUserWithEmailAndPassword(email, pass);
} catch (error) {
console.log(error.message);
}
})
btnLogOut.addEventListener('click', e => {
event.preventDefault()
firebase.auth().signOut();
});
firebase.auth().onAuthStateChanged(firebaseUser => {
if(firebaseUser) {
window.location.replace('https://www.camisite.alenieto97.now.sh/home.html')
btnLogin.style.display = 'none'
btnSignUp.style.display = 'none'
btnLogOut.style.display = ''
} else {
console.log('not logged in')
btnLogOut.style.display = 'none'
btnLogin.style.display = ''
btnSignUp.style.display = ''
}
我删除了 firebase.config 的每个阵营。