checkAuth: does not work when a page is called directly

Hello

I want to check Auth and redirect to a login page beforeEnter .
It works when accessing the website from the homepage, but if I go to the page “users”, reload, it does not work anymore.
Problem is, that jquery is loaded in index and is not loaded, if reloading users-page.

  1. How to solve this?

  2. Is there a way to checkAuth with beforeEnter for my homepage “/” and redirect to login? beforeEnteron my homepage has no effect.

Thank you!

   function checkAuth({ to, from, resolve, reject }) {

      const router = this;
      var session;
      $.ajaxSetup({cache: false})
      $.get('get_session.php', function (data) {
          session = JSON.parse(data);

          if (session.member_permission == null || session.member_permission < 2) {
            reject();
            router.navigate('/login/');
            return;
          } else {
            resolve();
          }

      });

    }

Don’t use jQuery for requests, use browsers fetch method Fetch API - Web APIs | MDN

Perfect, thank you!

function checkAuth({ to, from, resolve, reject }) {

  const router = this;

  fetch('get_session.php', {cache: 'no-cache'})

  .then(response => response.json())
  .then(data => {

if (data.member_permission == null || data.member_permission < 2) {
      reject();
      router.navigate('/login/');
      return;
    } else {
      resolve();
    }
  });


  }