Add ensureAuthenticated function