4👍
I think you lost your scope using function
.
Solve it by using es6 syntax (if you can afford/using babel), (user) => { .. }
.
Or by setting something like var _this = this;
in the main login function and referencing that.
Source:stackexchange.com