balena-cli/lib/cli-modules/auth/auth.coffee

28 lines
689 B
CoffeeScript
Raw Normal View History

2014-11-14 13:51:59 +00:00
async = require('async')
server = require('../../server/server')
2014-11-14 13:51:59 +00:00
token = require('../../token/token')
2014-11-14 13:51:59 +00:00
exports.authenticate = (credentials, callback) ->
server.post '/login_', credentials, (error, response) ->
return callback(error, response?.body)
exports.login = (credentials, callback) ->
2014-11-14 13:51:59 +00:00
async.waterfall([
(callback) ->
exports.authenticate(credentials, callback)
(authToken, callback) ->
token.saveToken(authToken, callback)
], callback)
# Handy aliases
exports.isLoggedIn = token.hasToken
exports.getToken = token.getToken
# TODO: Maybe we should post to /logout or something
# like that to invalidate the token on the server?
exports.logout = token.clearToken