replace hook by middleware