Created
December 24, 2017 05:09
-
-
Save abachuk/18bbf4fe0ffed5224c316e0545c8cd2a to your computer and use it in GitHub Desktop.
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
// after all babel and webpack configs | |
import AWS from 'aws-sdk'; | |
import { CognitoUserPool } from 'amazon-cognito-identity-js'; | |
export default function signupHandler(body) { | |
const userData = JSON.parse(body); | |
AWS.config.region = 'us-east-1'; | |
const poolData = { | |
UserPoolId: 'us-east-1_xxxxxxx', | |
ClientId: 'xxxxxxxxxxxxxxxxxxx', // clientId from cognito app client | |
}; | |
const userPool = new CognitoUserPool(poolData); | |
const attributeList = []; | |
const attributeEmail = { | |
Name: 'email', | |
Value: userData.email, | |
}; | |
attributeList.push(attributeEmail); | |
return new Promise((resolve, reject) => { | |
userPool.signUp(userData.username, userData.password, attributeList, null, (error, result) => { | |
if (error) return reject(error); | |
const response = { | |
statusCode: 200, | |
headers: { 'Content-Type': 'application/json'}, | |
body: JSON.stringify({ | |
username: result.user.username, | |
}), | |
isBase64Encoded: false, | |
}; | |
return resolve(response); | |
}, | |
); | |
}); | |
} | |
exports.signup = async (event, context, callback) => { | |
try { | |
const signup = await signupHandler(event.body); | |
callback(null, signup); | |
} catch (error) { | |
callback(error); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment