You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
Add support for Redis 6 auth pass [user]
(#1508)
* Add support for `auth pass user` * fix lint issues * fix typo * fix more lint issues * more lints fixes * reverse password user order * update redis-commands * Update individualCommands.js Clean code * Update individualCommands.js * Update auth.spec.js * Update index.js Co-authored-by: Leibale Eidelman <leibale1998@gmail.com>
This commit is contained in:
@@ -180,7 +180,7 @@ Multi.prototype.info = Multi.prototype.INFO = function info (section, callback)
|
||||
return this;
|
||||
};
|
||||
|
||||
function auth_callback (self, pass, callback) {
|
||||
function auth_callback (self, pass, user, callback) {
|
||||
return function (err, res) {
|
||||
if (err) {
|
||||
if (no_password_is_set.test(err.message)) {
|
||||
@@ -191,7 +191,7 @@ function auth_callback (self, pass, callback) {
|
||||
// If redis is still loading the db, it will not authenticate and everything else will fail
|
||||
debug('Redis still loading, trying to authenticate later');
|
||||
setTimeout(function () {
|
||||
self.auth(pass, callback);
|
||||
self.auth(user, pass, callback);
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
@@ -200,25 +200,37 @@ function auth_callback (self, pass, callback) {
|
||||
};
|
||||
}
|
||||
|
||||
RedisClient.prototype.auth = RedisClient.prototype.AUTH = function auth (pass, callback) {
|
||||
RedisClient.prototype.auth = RedisClient.prototype.AUTH = function auth (pass, user, callback) {
|
||||
debug('Sending auth to ' + this.address + ' id ' + this.connection_id);
|
||||
|
||||
// Backward compatibility support for auth with password only
|
||||
if (user instanceof Function) {
|
||||
callback = user;
|
||||
user = null;
|
||||
}
|
||||
// Stash auth for connect and reconnect.
|
||||
this.auth_pass = pass;
|
||||
this.auth_user = user;
|
||||
var ready = this.ready;
|
||||
this.ready = ready || this.offline_queue.length === 0;
|
||||
var tmp = this.internal_send_command(new Command('auth', [pass], auth_callback(this, pass, callback)));
|
||||
var tmp = this.internal_send_command(new Command('auth', user ? [user, pass] : [pass], auth_callback(this, pass, user, callback)));
|
||||
this.ready = ready;
|
||||
return tmp;
|
||||
};
|
||||
|
||||
// Only works with batch, not in a transaction
|
||||
Multi.prototype.auth = Multi.prototype.AUTH = function auth (pass, callback) {
|
||||
Multi.prototype.auth = Multi.prototype.AUTH = function auth (pass, user, callback) {
|
||||
debug('Sending auth to ' + this.address + ' id ' + this.connection_id);
|
||||
|
||||
// Backward compatibility support for auth with password only
|
||||
if (user instanceof Function) {
|
||||
callback = user;
|
||||
user = null;
|
||||
}
|
||||
// Stash auth for connect and reconnect.
|
||||
this.auth_pass = pass;
|
||||
this.queue.push(new Command('auth', [pass], auth_callback(this._client, callback)));
|
||||
this.auth_user = user;
|
||||
this.queue.push(new Command('auth', user ? [user, pass] : [pass], auth_callback(this._client, pass, user, callback)));
|
||||
return this;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user