Merge pull request #328 from resin-io/fix/innacurate-invalid-2fa-code

Only throw "Invalid 2FA code" if we're sure that's the cause
This commit is contained in:
Juan Cruz Viotti 2016-03-17 15:38:15 -04:00
commit 4fc8b130f8
2 changed files with 9 additions and 4 deletions

View File

@ -56,9 +56,12 @@ limitations under the License.
message: 'Two factor auth challenge:',
name: 'code',
type: 'input'
}).then(resin.auth.twoFactor.challenge)["catch"](function() {
}).then(resin.auth.twoFactor.challenge)["catch"](function(error) {
return resin.auth.logout().then(function() {
throw new Error('Invalid two factor authentication code');
if (error.name === 'ResinRequestError' && error.statusCode === 401) {
throw new Error('Invalid two factor authentication code');
}
throw error;
});
});
});

View File

@ -44,9 +44,11 @@ exports.authenticate = (options) ->
name: 'code'
type: 'input'
.then(resin.auth.twoFactor.challenge)
.catch ->
.catch (error) ->
resin.auth.logout().then ->
throw new Error('Invalid two factor authentication code')
if error.name is 'ResinRequestError' and error.statusCode is 401
throw new Error('Invalid two factor authentication code')
throw error
exports.askLoginType = ->
return form.ask