You are trying to call .then() on a function. .then() can only be called on a promise: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then
Make sure then your login function returns a promise. (It now returns nothing if the try succeeds.)