I know why the page was refreshing when it should not have. I had to add the restrict access function