Created
January 28, 2018 17:23
-
-
Save rickhernandezio/b991172f9f4b0565afc59e57cb29e096 to your computer and use it in GitHub Desktop.
Log user in using Cognito
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const authenticationData = { | |
Username: user.email, | |
Password: user.password, | |
}; | |
const authenticationDetails = new AuthenticationDetails(authenticationData); | |
const userData = { | |
Username: user.email, | |
Pool: this.userPool | |
}; | |
const cognitoUser = new CognitoUser(userData); | |
cognitoUser.authenticateUser(authenticationDetails, { | |
onSuccess: function (session) { | |
const tokens = { | |
accessToken: session.getAccessToken().getJwtToken(), | |
idToken: session.getIdToken().getJwtToken(), | |
refreshToken: session.getRefreshToken().getToken() | |
}; | |
cognitoUser['tokens'] = tokens; // Save tokens for later use | |
resolve(cognitoUser); // Resolve user | |
}, | |
onFailure: function (err) { | |
return reject(err); // Reject out errors | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment