take the code from github.com/NicholasTurner to fix getUserByIdentity nested where