Guest User

Untitled

a guest
May 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. const AWS = require("aws-sdk");
  2. const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
  3.  
  4. const clientID1 = process.env.client_id;
  5.  
  6. function registerUser(client, password, username, email){
  7. var params = {
  8. ClientId: client, /* required */
  9. Password: password, /* required */
  10. Username: username, /* required */
  11. UserAttributes: [
  12. {
  13. Name: 'email',
  14. Value: email
  15. }
  16. ]
  17. };
  18. cognitoidentityserviceprovider.signUp(params, function(err, data) {
  19. if (err) console.log(err, err.stack); // an error occurred
  20. else{
  21. console.log(data); // successful response
  22. return data;
  23. }
  24. });
  25. }
  26.  
  27.  
  28. function verifyInput(e){
  29. let data = {};
  30. try{
  31. data.password = e.password;
  32. data.username = e.username;
  33. data.email = e.email;
  34. } catch (e) {
  35. console.error(e);
  36. return false;
  37. }
  38. if (data.password === undefined) return false;
  39. if (data.username === undefined) return false;
  40. if (data.email === undefined) return false;
  41. return data;
  42. }
  43.  
  44. exports.handler = (event, context, callback) => {
  45. let check = verifyInput(event);
  46. if (check === false) return callback(null, "Registration Failed");
  47. let data = registerUser(clientID1, event.password, event.username, event.email);
  48. callback(null, "Registration Successful");
  49. };
Add Comment
Please, Sign In to add comment