0

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

4

2 回答 2

0

好吧,Mkam 是对的。网址错误。删除“www”后一切正常。从网址。

于 2020-05-04T01:59:58.343 回答
0

您是否尝试过使用根级别的网址?这是因为如果您的应用程序托管在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'
于 2020-05-03T05:00:37.233 回答