Skip to content

Commit

Permalink
build files
Browse files Browse the repository at this point in the history
  • Loading branch information
powerful23 committed Jan 18, 2018
1 parent b149923 commit 9cdbfa4
Show file tree
Hide file tree
Showing 8 changed files with 1,894 additions and 978 deletions.
42 changes: 29 additions & 13 deletions packages/aws-amplify-react-native/dist/Auth/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,46 @@ class AuthClass {

/**
* Sign up with username, password and other attrbutes like phone, email
* @param {String} username - The username to be signed up
* @param {String} password - The password of the user
* @param {String} email - The email of the user
* @param {String} phone_number - the phone number of the user
* @return {Promise} - A promise resolves callback data if success
* @param {String | object} attrs - The user attirbutes used for signin
* @param {String[]} restOfAttrs - for the backward compatability
* @return - A promise resolves callback data if success
*/
signUp(username, password, email, phone_number) {
signUp(attrs, ...restOfAttrs) {
if (!this.userPool) {
return Promise.reject('No userPool');
}

let username = null;
let password = null;
const attributes = [];
if (attrs && typeof attrs === 'string') {
username = attrs;
password = restOfAttrs ? restOfAttrs[0] : null;
const email = restOfAttrs ? restOfAttrs[1] : null;
const phone_number = restOfAttrs ? restOfAttrs[2] : null;
if (email) attributes.push({ Name: 'email', Value: email });
if (phone_number) attributes.push({ Name: 'phone_number', Value: phone_number });
} else if (attrs && typeof attrs === 'object') {
username = attrs['username'];
password = attrs['password'];
Object.keys(attrs).map(key => {
if (key === 'username' || key === 'password') return;
const ele = { Name: key, Value: attrs[key] };
attributes.push(ele);
});
} else {
return Promise.reject('The first parameter should either be non-null string or object');
}

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 });
}
logger.debug('signUp attrs:');
logger.debug(attributes);

return new Promise((resolve, reject) => {
this.userPool.signUp(username, password, attributes, null, function (err, data) {
Expand Down
Loading

0 comments on commit 9cdbfa4

Please sign in to comment.