Added optional bool to not set as current user when calling client.authenticateUser()
diff --git a/lib/client.js b/lib/client.js
index c337484..509b50c 100644
--- a/lib/client.js
+++ b/lib/client.js
@@ -107,12 +107,13 @@
},
authenticateUser: function(options) {
var self = this
- var callback = helpers.cb(helpers.args(arguments))
-
+ var args = helpers.args(arguments)
+ var callback = helpers.cb(args)
+ var setAsCurrentUser = (_.last(args.filter(_.isBoolean))) !== undefined ? _.last(args.filter(_.isBoolean)) : true
var UsergridUser = require('./user')
var currentUser = new UsergridUser(options)
currentUser.login(self, function(error, usergridResponse, token) {
- if (usergridResponse.ok) {
+ if (usergridResponse.ok && setAsCurrentUser) {
self.currentUser = currentUser
}
callback(error, usergridResponse, token)
diff --git a/tests/lib/client.auth.test.js b/tests/lib/client.auth.test.js
index c7f6bad..ad33987 100644
--- a/tests/lib/client.auth.test.js
+++ b/tests/lib/client.auth.test.js
@@ -202,8 +202,8 @@
it('should fail when called without a email (or username) and password', function() {
should(function() {
- var client = new UsergridClient()
- client.authenticateUser({})
+ var badClient = new UsergridClient()
+ badClient.authenticateUser({})
}).throw()
})
@@ -238,6 +238,18 @@
client.currentUser.auth.should.not.have.property('password')
})
+ it('should support an optional bool to not set as current user', function(done) {
+ var noCurrentUserClient = new UsergridClient()
+ noCurrentUserClient.authenticateUser({
+ username: config.test.username,
+ password: config.test.password,
+ email: email
+ }, false, function(err, r, t) {
+ should(noCurrentUserClient.currentUser).be.undefined()
+ done()
+ })
+ })
+
it('should support passing a UsergridUserAuth instance with a custom ttl', function(done) {
var newClient = new UsergridClient()
var ttlInMilliseconds = 500000