Hey all!
I have a node API that hits my kong layer whenever an actor in our system is updated. Im having trouble for the use case in which and actor is trying to update the username to a previously held name.
ie: user ‘Steve’ changes his name to ‘Steve1’, and then decides to change it back to ‘Steve’. But kong throws an error saying that it is unable to generate a new JWT for that consumer as the key ‘Steve’ is already in use. Im able to modify the consumer object itself with a new value, but once I try to return to an older, previously used but no longer active value, I am unable. Thoughts?
Here is a log of my authentication api during the above process. as you can see the ‘Steve’ consumer is created, and then once the username is updated to Steve1, it proceeds as normal, changing the value. But then a subsequent request to change the username back to ‘Steve’ results in this error being through of { key: 'already exists with value \'Steve\'' }
and then the remainder of the promise chain involved with creating a JWT rejects.
Ive toyed with trying to delete that specific key at various points in the chain of my promise, but it always seems to end up deleting the consumer Im trying to update.
this is my request to kong to modify the user and is the point of failure in my patch route for modifying consumers.
return new Promise(function(resolve,reject) {
if (useKong === 'true') {
request(
{
url: kongAdminUrl+'/consumers/'+obj.consumerId,
method: 'PATCH',
json: {
'username': obj.userName,
'custom_id': obj.spid
}
}, function(err,response,body) {
if (err) reject(err);
else {
if (isDefined(body) && (typeof body) == 'string') body = JSON.parse(body);
if (isDefined(body.id)) {
obj.consumerId = body.id;
console.log('Updated consumer \''+obj.userName+'\'');
resolve(obj);
} else {
console.log('ERROR updating consumer \''+obj.userName+'\'');
reject(new Error('failed to update kong consumer \''+obj.userName+'\''));
}
}
}
);
} else {
// Not using kong
resolve(obj);
}
});
}```