It would be nice to have this code exist inside the loginapi node module so you don't need to repeat it