Created
November 15, 2021 14:28
-
-
Save LHazy/748c94412a3d12cb999cf23ddf4207b2 to your computer and use it in GitHub Desktop.
Cognitoへのログインコード
This file contains hidden or 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
| // 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