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

How do I know if I provided an incorrect password? #164

Closed
naugtur opened this issue Sep 29, 2015 · 4 comments
Closed

How do I know if I provided an incorrect password? #164

naugtur opened this issue Sep 29, 2015 · 4 comments

Comments

@naugtur
Copy link

naugtur commented Sep 29, 2015

new Redis(options) with options.password being incorrect or missing, doesn't throw (not surprising, AUTH is async) and it doesn't emit end nor close, nor error.

How do I know if the AUTH command that happens in the background failed?

[edit]
It works if I call .auth myself, but otherwise, the error is swallowed. I even found one location which might be responsible for swallowing it: https://github.com/luin/ioredis/blob/master/lib/redis.js#L124

But switching to lazyConnect and connecting on my own would also resolve happily without reporting auth issues, so that's not all there is to it.

[one more edit]
Unfortunately, calling .auth on my own is not possible, because a "Ready check" is made, and it fails because auth was not made yet... So no workaround here.

@luin
Copy link
Collaborator

luin commented Sep 29, 2015

Yes, we may emit an event when the password is wrong. May be auth error.

@naugtur
Copy link
Author

naugtur commented Sep 29, 2015

So for the workaround to work:

enableReadyCheck: false in options is required, then:

redisInstance.on("connect", function () {
    redisInstance.auth("pawsword", function (err, res) {
        if (err) {
            console.error(err);
            redisInstance.disconnect()
            process.exit();

        }

    })
});

But I'd appreciate a way to catch the initial built-in auth failure.

redisInstance.on("error",function(authError){})

^would be the way to go imho

@luin
Copy link
Collaborator

luin commented Sep 29, 2015

error event is a special event that would crash the app if there's no listener for it. I would go for another event name like auth error. 😆

@naugtur
Copy link
Author

naugtur commented Sep 29, 2015

Well, I'm on this camp that prefers when errors have to be handled ;) but ok.
If I can suggest something I'd not put a space in the event name for the sake of people coming from jQuery where it means 2 events ;)

@luin luin closed this as completed in 03acced Oct 2, 2015
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