window.location.replacereturn此网站无法提供安全连接,它发送了无效响应.Vercel部署和香



所以我正在进一步开发这个网站,这次我添加了一个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.的每个营地

您尝试过使用根级别的url吗?这是因为如果你的应用程序托管在http://localhost或任何其他域中,那么你试图将url更改为https://www.camisite.alenieto97.now.sh,它将抛出SECURITY_ERROR。使用根级别的url可以解决这类问题。此外,你们为什么要硬编码那个些可能会改变后者的域名?

firebase.auth().onAuthStateChanged(firebaseUser => {
if(firebaseUser) {
window.location.replace('/home.html')
btnLogin.style.display = 'none'
Mkam是对的。url错误。从网址中删除"www."后,一切都很顺利。

最新更新