diff --git a/src/base-apis.js b/src/base-apis.js index 6752ad1c5..671ddcb01 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -120,6 +120,20 @@ MatrixBaseApis.prototype.makeTxnId = function() { // Registration/Login operations // ============================= +/** + * Check whether a username is available prior to registration. An error response + * indicates an invalid/unavailable username. + * @param {string} username The username to check the availability of. + * @return {module:client.Promise} Resolves: to `true`. + */ +MatrixBaseApis.prototype.isUsernameAvailable = function(username) { + return this._http.authedRequest( + undefined, "GET", '/register/available', { username: username }, + ).then((response) => { + return response.available; + }); +}; + /** * @param {string} username * @param {string} password