Skip to content

Commit

Permalink
fix(connections): fix can send empty auth info
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfscream committed Dec 19, 2023
1 parent b1f0e3f commit 371e17a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils/mqttUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ const getClientOptions = (record: ConnectionModel): IClientOptions => {
}
if (password !== '') {
options.password = password
if (username === undefined || username === '') {
options.username = ''
}
}
// SSL
if (ssl) {
Expand Down Expand Up @@ -148,7 +151,7 @@ export const createClient = (
topicAliasMaximum: options.properties ? options.properties.topicAliasMaximum : undefined,
}
const { password, username, protocolVersion } = tempOptions
if (password && username === undefined && protocolVersion !== 5) {
if (password && (username === undefined || username === '') && protocolVersion !== 5) {
return reject(new Error('MQTT 3.1.1 requires a Username if a Password is set'))
}
const curConnectClient: MqttClient = mqtt.connect(url, tempOptions)
Expand Down

0 comments on commit 371e17a

Please sign in to comment.