Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect fails silently if no username is provided but only a password #1685

Open
AuspeXeu opened this issue Sep 5, 2023 · 1 comment
Open

Comments

@AuspeXeu
Copy link

AuspeXeu commented Sep 5, 2023

Consider the following piece of code.

import Server, { AuthenticateError } from 'aedes';
import * as net from 'net';
import { connect } from 'mqtt';

const mqttServer = new Server({
  authenticate(_, __, password, callback) {
    if (password?.toString() !== 'MY GOOD SECURE PASSWORD') {
      const error: AuthenticateError = { ...new Error('Auth error'), returnCode: 4 };
      callback(error, null);
    } else {
      callback(null, true);
    }
  }
});

net
  .createServer(mqttServer.handle)
  .on('error', (err) => console.error(err))
  .listen(1883, '192.168.0.21', () => {
    console.log(`Aedes server listening on 192.168.0.21:1883`);
    const mqttClient = connect('mqtt://192.168.0.21', {
      // username: 'does-not-matter',
      password: 'MY GOOD SECURE PASSWORD',
      reconnectPeriod: 2 * 1000
    })
  })

In this example, the client will never connect and you will never find out why until you comment the username back in.

@robertsLando
Copy link
Member

Would you like to submit a PR to fix this?

rts-rob added a commit to rts-rob/MQTT.js that referenced this issue Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants