0

I am having trouble with not allowing non users of my site accessing the page after they login. After an individual registers on the site and becomes a user they are brought to /maindash.html and that is basically where the user goes once they register or login. But when someone else pastes the redirected URL it works for them even though they are not a user like if someone types website.com/maindash.html they are redirected to the user page even though they have not registered.

Here is my JS code for login

login.addEventListener('click' , e => {
const emailSignin = signInEmail.value;
const passwordSignin = signInPassword.value;
const auth = firebase.auth(); 

const promise =  auth.signInWithEmailAndPassword(emailSignin, passwordSignin);
promise.catch(e => console.log(e.message));
  });

     firebase.auth().onAuthStateChanged(firebaseUser => {
  if (firebaseUser) {
      window.location = '/NovaCoreInc/maindash.html'
  }
  })

Here is my JS code for registering

if (password === reenter) {
    const promise =  auth.createUserWithEmailAndPassword(email , password);
    promise.catch(e => console.log(e.message));

    //Creating the Database for the Users using realtime mf (SAVE THE DATABSE INFO)
    database.ref('users/' + name).set({
        Email: email,
        Password: password,
        Gender: gender,
        Industry: industry
    });
} else {
    passwordError.style.display = 'block'
}

});

 firebase.auth().onAuthStateChanged(firebaseUser => {
  if (firebaseUser) {
      window.location = '/NovaCoreInc/maindash.html'
  }
 })

my main problem is how to keep no registered users away the pages that registered users are authorized for?

thank you

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 1
    If you're using Firebase Hosting, you can't really keep them away from the HTML+JavaScript pages. See https://stackoverflow.com/questions/27212004/can-firebase-hosting-restrict-access-to-resources But you *can* keep them away from the data in your database with server-side security rules. See https://firebase.google.com/docs/database/security/user-security – Frank van Puffelen Nov 27 '18 at 01:56
  • @FrankvanPuffelen I’m hosting it on GitHub but I’ll take a look at the links you have thanks you ! –  Nov 27 '18 at 01:57
  • From a quick scan it seems that Github pages also is all-public, without an option for access control: https://stackoverflow.com/a/11007746 – Frank van Puffelen Nov 27 '18 at 03:15

0 Answers0