amazon-archives / amazon-cognito-auth-js

The Amazon Cognito Auth SDK for JavaScript simplifies adding sign-up, sign-in with user profile functionality to web apps.
Apache License 2.0
424 stars 232 forks source link

Is promisifying userhandler a bad idea? #162

Open 10ky opened 5 years ago

10ky commented 5 years ago

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?

chamathsilva commented 5 years ago

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 )