diff --git a/packages/binding-mqtt/src/mqtt-client.ts b/packages/binding-mqtt/src/mqtt-client.ts index 2b1f2d15a..bbb9d1cf5 100644 --- a/packages/binding-mqtt/src/mqtt-client.ts +++ b/packages/binding-mqtt/src/mqtt-client.ts @@ -40,7 +40,7 @@ export default class MqttClient implements ProtocolClient { this.scheme = "mqtt" + (secure ? "s" : ""); } - private client: mqtt.MqttClient = undefined; + private client?: mqtt.MqttClient; public subscribeResource( form: MqttForm, @@ -166,8 +166,13 @@ export default class MqttClient implements ProtocolClient { const security: TD.SecurityScheme = metadata[0]; if (security.scheme === "basic") { - this.config.username = credentials.username; - this.config.password = credentials.password; + if (credentials === undefined) { + // FIXME: This error message should be reworded and adapt to logging convention + throw new Error("binding-mqtt: security wants to be basic but you have provided no credentials"); + } else { + this.config.username = credentials.username; + this.config.password = credentials.password; + } } return true; } diff --git a/packages/binding-mqtt/src/mqtt.ts b/packages/binding-mqtt/src/mqtt.ts index b5e5418a4..459557c34 100644 --- a/packages/binding-mqtt/src/mqtt.ts +++ b/packages/binding-mqtt/src/mqtt.ts @@ -47,7 +47,7 @@ export class MqttForm extends Form { } export interface MqttClientConfig { - // username & password are redundated here (also find them in MqttClientSecurityParameters) + // username & password are redundant here (also find them in MqttClientSecurityParameters) // because MqttClient.setSecurity() method can inject authentication credentials into this interface // which will be then passed to mqtt.connect() once for all username?: string; diff --git a/packages/binding-mqtt/tsconfig.json b/packages/binding-mqtt/tsconfig.json index e9fa7c062..df9cd1d90 100644 --- a/packages/binding-mqtt/tsconfig.json +++ b/packages/binding-mqtt/tsconfig.json @@ -2,7 +2,8 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "dist", - "rootDir": "src" + "rootDir": "src", + "strict": true }, "include": ["src/**/*"], "references": [{ "path": "../td-tools" }, { "path": "../core" }]