middleware to check for unique index