Switched back middleware order and added check for user in the middleware [MJ-389]