Guest User

Untitled

a guest
Jan 22nd, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. async function signUp(email, password) {
  2. try {
  3. const cognito = new AWS.CognitoIdentityServiceProvider()
  4. await cognito.adminCreateUser({
  5. UserPoolId: process.env.USER_POOL_ID,
  6. Username: email,
  7. MessageAction: 'SUPPRESS',
  8. TemporaryPassword: password,
  9. }).promise()
  10.  
  11. const initAuthResponse = await cognito.adminInitiateAuth({
  12. AuthFlow: 'ADMIN_NO_SRP_AUTH',
  13. ClientId: process.env.CLIENT_ID,
  14. UserPoolId: process.env.USER_POOL_ID,
  15. AuthParameters: {
  16. USERNAME: email,
  17. PASSWORD: password
  18. }
  19. }).promise()
  20.  
  21. if (initAuthResponse.ChallengeName === 'NEW_PASSWORD_REQUIRED') {
  22. await cognito.adminRespondToAuthChallenge({
  23. ChallengeName: 'NEW_PASSWORD_REQUIRED',
  24. ClientId: process.env.CLIENT_ID,
  25. UserPoolId: process.env.USER_POOL_ID,
  26. ChallengeResponses: {
  27. USERNAME: email,
  28. NEW_PASSWORD: password,
  29. },
  30. Session: initAuthResponse.Session
  31. }).promise()
  32. }
  33. } catch (err) {
  34. throw err
  35. }
  36. }
Add Comment
Please, Sign In to add comment