Search code examples
javascriptfirebasewindow.locationinsecure-connection

window.location.replace returns This site can’t provide a secure connection, it sent an invalid response. Vercel deployment and vanilla JS


So I'm further developing this website, this time I'm adding a firebase login that should redirect you to the main page once you are logged. However I get "This site can’t provide a secure connection, it sent an invalid response" with every window.location method. Everything works just fine once I comment that line out. I went across all stackoverflow related questions and js documentation and can't seem to find the answer, so any help would be very well received.

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 = ''
    }

I deleted every camp of firebase.config.


Solution

  • Well Mkam was right. The url was wrong. It all worked out fine after removing the "www." from the url.