login: refactor login by getting it out from the endpoints code