amazon-cognito-auth-js icon indicating copy to clipboard operation
amazon-cognito-auth-js copied to clipboard

Is promisifying userhandler a bad idea?

Open 10ky opened this issue 7 years ago • 1 comments

I would like to use Promise instead of callbacks. Something like this:

var auth = new CognitoAuth(configData)

auth.userhandler = {
  onSuccess: promisifiedSuccess,
  onFailure: promisifiedFailure
}

 promisifiedSuccess(result) {
    return Promise.resolve(result)
 }

 promisifiedFailure(err) {
    return Promise.reject(err)
 }

I was wondering if I can use redux thunk to make a async call of getSession and handle the callbacks as Promises.

What is the best way to do this? It looks to me amazon-cognito-auth-js is not written as a ES6 lib. Any chance it will be upgraded to ES6 or later?

10ky avatar Oct 16 '18 04:10 10ky

I came across the same requirement. Especially when using CodeGrantFlow. Therefore I modified the Amazon Cognito Auth source to support to promise.

https://www.npmjs.com/package/amazon-cognito-auth-js-promises ( Updated Documentation with promises example )

chamathsilva avatar Oct 16 '18 10:10 chamathsilva