diff --git a/lib/user-methods.js b/lib/user-methods.js index 4035bc85..d4cbe209 100644 --- a/lib/user-methods.js +++ b/lib/user-methods.js @@ -132,18 +132,19 @@ function _authenticate(userConstructor, server, json, callback) { headers: postHeaders, open_timeout: 5000 }; + const promise = performFetch(url, options) .then((response) => { if (response.status !== 200) { - return response.json().then((body) => callback(new AuthError(body))); + return response.json().then((body) => Promise.reject(new AuthError(body))); } else { return response.json().then(function (body) { // TODO: validate JSON const token = body.refresh_token.token; const identity = body.refresh_token.token_data.identity; const isAdmin = body.refresh_token.token_data.is_admin; - callback(undefined, userConstructor.createUser(server, identity, token, false, isAdmin)); - }) + return userConstructor.createUser(server, identity, token, false, isAdmin); + }); } }); @@ -193,8 +194,8 @@ const staticMethods = { const message = "register(..., callback) is now deprecated in favor of register(): Promise. This function argument will be removed in future versions."; (console.warn || console.log).call(console, message); } - _authenticate(this, server, json, callback); - + + return _authenticate(this, server, json, callback); }, login(server, username, password, callback) { @@ -209,7 +210,8 @@ const staticMethods = { const message = "login(..., callback) is now deprecated in favor of login(): Promise. This function argument will be removed in future versions."; (console.warn || console.log).call(console, message); } - _authenticate(this, server, json, callback); + + return _authenticate(this, server, json, callback); }, registerWithProvider(server, options, callback) { @@ -240,7 +242,8 @@ const staticMethods = { const message = "registerWithProvider(..., callback) is now deprecated in favor of registerWithProvider(): Promise. This function argument will be removed in future versions."; (console.warn || console.log).call(console, message); } - _authenticate(this, server, json, callback); + + return _authenticate(this, server, json, callback); }, _refreshAccessToken: refreshAccessToken