Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor signup attributes as objects #79

Closed
wants to merge 11 commits into from
Next

Refactoring Auth SignUp to take attributes as objects

  • Loading branch information...
Sharma
Sharma committed Dec 18, 2017
commit 379ee152863800ced366fdd58f72ee607445715a
@@ -110,9 +110,15 @@ class AuthClass {
if (!password) { return Promise.reject('Password cannot be empty'); }

const attributes = [];
if (email) { attributes.push({Name: 'email', Value: email}); }
if (phone_number) { attributes.push({Name: 'phone_number', Value: phone_number}); }

if(email) {
if(typeof(email) === 'string'){
attributes.push({Name: 'email', Value: email});
if (phone_number) { attributes.push({Name: 'phone_number', Value: phone_number}); }
} else {
attributes = email;
}
}

return new Promise((resolve, reject) => {
this.userPool.signUp(username, password, attributes, null, function(err, data) {
if (err) { reject(err); } else { resolve(data); }
@@ -99,15 +99,22 @@ export default class AuthClass {
* @param {Object} attributeList - Other attributes
* @return - A promise resolves callback data if success
*/
public signUp(username: string, password: string, email: string, phone_number: string): Promise<any> {
public signUp(username: string,
password: string,
email?: string|Array<Object>,

This comment has been minimized.

Copy link
@mlabieniec

mlabieniec Dec 21, 2017

Contributor

Update attributes (email) argument to be an object {} allowing k/v pairs for where k is attribute name

phone_number?: string): Promise<any> {
if (!this.userPool) { return Promise.reject('No userPool'); }
if (!username) { return Promise.reject('Username cannot be empty'); }
if (!password) { return Promise.reject('Password cannot be empty'); }

const attributes = [];
if (email) { attributes.push({Name: 'email', Value: email}); }
if (phone_number) { attributes.push({Name: 'phone_number', Value: phone_number}); }

let attributes = [];
if(typeof(email) === 'string'){
if (email) { attributes.push({Name: 'email', Value: email}); }
if (phone_number) { attributes.push({Name: 'phone_number', Value: phone_number}); }
}
else {
attributes = email;
}
return new Promise((resolve, reject) => {
this.userPool.signUp(username, password, attributes, null, function(err, data) {
if (err) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.