implemented middleware ensureAuthenticated