1.0.1 • Published 5 years ago
amazon-cognito-identity-promise v1.0.1
Amazon Cognito Identitiy Promise
AWS Cognito for JS uses callbacks.
These make me want to die.
This library acts as an extension with promises
Promises
No more callback hell. I can code peacefully.
// Before
cognitoUser.authenticateUser(
authDetails,
{
onSuccess: (session, userConfirmationNecessary) => {
console.log(session, userConfrimationNecessary, "I want to die")
},
onFailure: (err) => {
console.error(err, "Help")
},
}
)
// This library
(async () => {
try {
const [session, userConfrimationNecessary] =
await cognitoUser.authenticateUser(authDetails)
console.log(session, userConfrimationNecessary, "This is nice")
} catch (err) {
console.error(err, "Normal rejection handling")
}
})
// Or if you prefer
const authenticate = cognitoUser.authenticateUser(authDetails)
Promise.resolve(authenticate).then(([session, userConfrimationNecessary]) => {
console.log(session, userConfrimationNecessary, "This is also nice")
})
.catch((err) => {
console.error(err, "Also normal rejection handling")
})
Getters and Setters
For (almost) every method that is prefixed with get
or set
, a getter or setter has been created in addition to that method
// Before
cognitoUser.setSignInUserSession(myUserSession)
cognitoUser.getSignInUserSession()
// After
cognitoUser.setSignInUserSession(myUserSession)
cognitoUser.signInUserSession = myUserSession
cognitoUser.getSignInUserSession()
cognitoUser.signInUserSession