refactor secure cookie check