Merge pull request #184 from resin-io/jviotti/fix/token-auth

Check token validity against the API when login
This commit is contained in:
Juan Cruz Viotti 2015-09-05 20:48:22 +03:00
commit 72f34031a9
2 changed files with 12 additions and 1 deletions

View File

@ -41,7 +41,14 @@
type: 'input'
});
});
}).then(resin.auth.loginWithToken).then(resin.auth.whoami).tap(function(username) {
}).then(resin.auth.loginWithToken).then(function(token) {
return resin.auth.isLoggedIn().then(function(isLoggedIn) {
if (isLoggedIn) {
return token;
}
throw new Error('Authentication failed');
});
}).then(resin.auth.whoami).tap(function(username) {
console.info("Successfully logged in as: " + username);
return events.send('user.login');
}).nodeify(done);

View File

@ -48,6 +48,10 @@ exports.login =
type: 'input'
.then(resin.auth.loginWithToken)
.then (token) ->
resin.auth.isLoggedIn().then (isLoggedIn) ->
return token if isLoggedIn
throw new Error('Authentication failed')
.then(resin.auth.whoami)
.tap (username) ->
console.info("Successfully logged in as: #{username}")