diff --git a/docs/Client.md b/docs/Client.md index a0c11c2f..713b028d 100644 --- a/docs/Client.md +++ b/docs/Client.md @@ -72,6 +72,15 @@ It is available only after `CONNACK (rc=0)`, otherwise it is `null` in cases: - after `CONNACK (rc!=0)` response - `connectionError` raised by aedes +## client.username + +- `` __Default__: `null` + +Client username, specified by CONNECT packet. + +It is available only after a successful call to `aedes.authenticate()`, where it +will be set to the username specifed by the client, or `null` if no username was supplied. + ## client.clean - `` __Default__: `true` diff --git a/lib/handlers/connect.js b/lib/handlers/connect.js index 14865f36..5a42ce96 100644 --- a/lib/handlers/connect.js +++ b/lib/handlers/connect.js @@ -98,9 +98,10 @@ function init (client, packet, done) { function authenticate (arg, done) { const client = this.client client.pause() + let username = this.username; client.broker.authenticate( client, - this.packet.username, + username, this.packet.password, negate) @@ -113,6 +114,10 @@ function authenticate (arg, done) { } if (!err && successful) { client._authorized = true + if (typeof(client.username) == "undefined") { + // check it's undefined, it could have been set in preConnect + client.username = username || null; + } return done() }