smarter user middleware