Fix bug in auth middleware