Why some of the API such as globalSignOut,getDevice,forgetDevice require onSuccess and onFailure function in the callback? Can they just follow universal function(err, data) signature?
especially, the globalSignOut function expect callback to be a function and also with onFailure, onSuccess function attached.
globalSignOut(callback) {
if (this.signInUserSession == null || !this.signInUserSession.isValid()) {
return callback(new Error('User is not authenticated'), null);
}
this.client.makeUnauthenticatedRequest('globalSignOut', {
AccessToken: this.signInUserSession.getAccessToken().getJwtToken(),
}, err => {
if (err) {
return callback.onFailure(err);
}
this.clearCachedTokens();
return callback.onSuccess('SUCCESS');
});
return undefined;
}
The design of the callbacks was done largely to keep consistency between this and Cognito's sync SDK. A change is under consideration, however, as you can see from #88
@jbailey2010 I think it's 2 issues, one is to fix the mixed style callback function while #88 is for adding promise support.
Thanks Michael, we are definitely considering making changes to the callback style. However, at this point, that would be a breaking change so it has to be planned and carried out carefully.
@itrestian could it be possible to do a check for given callback, call it if it's a function while invoke onSuccess,onFailure if it's a object. Seems not going to break anything.
That's the change I suggested in #88 (note that I am not an Amazon employee though), since to support promises in existing APIs without breaking back-compat it's simpler to do that than not.
It might be an earlier PR, but I want to get my tests branch up with decent coverage first.
Is the callback argument ever called by itself?
If that's not the case, then a simple fix would be to rename callback to options because it's just an object with callback functions in it.
That would be more semantically correct
Don't think callback is called on it's own. Closing this in favour of https://github.com/aws/amazon-cognito-identity-js/issues/238.
@itrestian You are closing these issues way too early mate.
Most helpful comment
@itrestian You are closing these issues way too early mate.