Updated the permission middleware