Skip to content

Instantly share code, notes, and snippets.

@LHazy
Created November 15, 2021 14:28
Show Gist options
  • Save LHazy/748c94412a3d12cb999cf23ddf4207b2 to your computer and use it in GitHub Desktop.
Save LHazy/748c94412a3d12cb999cf23ddf4207b2 to your computer and use it in GitHub Desktop.
Cognitoへのログインコード
// npm install @aws-sdk/client-cognito-identity
import {
AuthenticationDetails,
CognitoUserPool,
CognitoUserAttribute,
CognitoUser,
} from 'amazon-cognito-identity-js';
var poolData = {
UserPoolId: '',
ClientId: '',
};
function login(email, password) {
const authDetails = new AuthenticationDetails({
Username: email,
Password: password
});
const userPool = new CognitoUserPool(poolData);
const cognitoUser = new CognitoUser({
Username: email,
Pool: userPool
});
cognitoUser.authenticateUser(authDetails, {
onSuccess: (result) => {
const accessToken = result.getAccessToken().getJwtToken();
console.log(accessToken);
},
onFailure: function(err) {
alert(err.message || JSON.stringify(err));
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment