Modified middleware implementation for auth support. Fixed session destroy callback