Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const AWS = require("aws-sdk");
- const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
- const clientID1 = process.env.client_id;
- function registerUser(client, password, username, email){
- var params = {
- ClientId: client, /* required */
- Password: password, /* required */
- Username: username, /* required */
- UserAttributes: [
- {
- Name: 'email',
- Value: email
- }
- ]
- };
- cognitoidentityserviceprovider.signUp(params, function(err, data) {
- if (err) console.log(err, err.stack); // an error occurred
- else{
- console.log(data); // successful response
- return data;
- }
- });
- }
- function verifyInput(e){
- let data = {};
- try{
- data.password = e.password;
- data.username = e.username;
- data.email = e.email;
- } catch (e) {
- console.error(e);
- return false;
- }
- if (data.password === undefined) return false;
- if (data.username === undefined) return false;
- if (data.email === undefined) return false;
- return data;
- }
- exports.handler = (event, context, callback) => {
- let check = verifyInput(event);
- if (check === false) return callback(null, "Registration Failed");
- let data = registerUser(clientID1, event.password, event.username, event.email);
- callback(null, "Registration Successful");
- };
Add Comment
Please, Sign In to add comment