added check to ensure a user is logged into the pages and apis
changed the api redirect to 401 error when attempting to access it without logging in