0

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.

  • 1
    are you able to open the redirected website in your browser? I opened it and its seems like the website is either down or not working. – mkamranhamid May 03 '20 at 04:45

2 Answers2

0

Have you tried with a root level url? Its because if your app is hosted in http://localhost or any other domain then you are trying to change url to https://www.camisite.alenieto97.now.sh it will throw SECURITY_ERROR. Using root level url will resolve that kind of problem. Moreover why would you hardcoded domain name that may change latter?

firebase.auth().onAuthStateChanged(firebaseUser => {
    if(firebaseUser) {
        window.location.replace('/home.html')
        btnLogin.style.display = 'none'
Tito
  • 663
  • 1
  • 8
  • 14
0

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