Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const p = new Promise((res, rej)=>{
// we create an array for our attributes that we want to update, and push all `CognitoUserAttribute` objects into it
const attributeList = []
// loop through the `attrs` array to create our `CognitoUserAttribute` objects
for(let a = 0; a
const p = new Promise((res, rej)=>{
// we create an array for our attributes that we want to update, and push all `CognitoUserAttribute` objects into it
const attributeList = []
// loop through the `attrs` array to create our `CognitoUserAttribute` objects
for(let a = 0; a
return new Promise((resolve, reject) => {
const dataEmail = { Name: 'email', Value: email }
const dataFirstName = { Name: 'given_name', Value: firstName }
const dataLastName = { Name: 'family_name', Value: lastName }
const attributeList = [
new CognitoUserAttribute(dataEmail),
new CognitoUserAttribute(dataFirstName),
new CognitoUserAttribute(dataLastName),
]
userPool.signUp(email, password, attributeList, null, (error, result) => {
log(error, result)
if (error) {
// TODO this code shouldn't know about graphql errors. refactor to use separate layers
if (error.code === 'UsernameExistsException') {
reject(new UserError(ERRORS.EmailAlreadyTaken))
} else {
reject(error)
}
return
}
resolve({ id: result.userSub, email })
})
return new Promise((resolve, reject) => {
const dataEmail = { Name: 'email', Value: email }
const dataFirstName = { Name: 'given_name', Value: firstName }
const dataLastName = { Name: 'family_name', Value: lastName }
const attributeList = [
new CognitoUserAttribute(dataEmail),
new CognitoUserAttribute(dataFirstName),
new CognitoUserAttribute(dataLastName),
]
userPool.signUp(email, password, attributeList, null, (error, result) => {
log(error, result)
if (error) {
// TODO this code shouldn't know about graphql errors. refactor to use separate layers
if (error.code === 'UsernameExistsException') {
reject(new UserError(ERRORS.EmailAlreadyTaken))
} else {
reject(error)
}
return
}
resolve({ id: result.userSub, email })
poolData = require('./poolData').poolData;
} else {
poolData = {
UserPoolId : process.env.REACT_APP_Auth_UserPoolId,
ClientId : process.env.REACT_APP_Auth_ClientId
};
}
var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
var attributeList = [];
var dataEmail = {
Name : 'email',
Value : model.email
};
var attributeEmail = new AmazonCognitoIdentity.CognitoUserAttribute(dataEmail);
attributeList.push(attributeEmail);
// Necessary becuase the closure has no access to this.props
let nestedProp = this.props;
let self = this
userPool.signUp(model.email, model.password, attributeList, null, function(err, result) {
if (err) {
toast.warn(err.message, {
position: "top-center",
autoClose: 4000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
});
attributes.forEach((item) => {
// if the attribute concerns the phone number
if (item.Name === 'phone_number') {
// do nothing, rather use profileEditPhoneNumber
// as there are some additionals checks concerning MFA to perform
}
// if the attribute has a value, update it with the new value
else if (item.Value !== null) {
const attribute = new AmazonCognitoIdentity.CognitoUserAttribute(item);
attributeUpdateList.push(attribute);
}
// otherwise, delete the attribute for that user
else {
attributeDeleteList.push(item.Name);
}
});
}
register(user: RegistrationUser, callback: CognitoCallback): void {
console.log("UserRegistrationService: user is " + user);
let attributeList = [];
let dataEmail = {
Name: 'email',
Value: user.email
};
let dataNickname = {
Name: 'nickname',
Value: user.name
};
attributeList.push(new CognitoUserAttribute(dataEmail));
attributeList.push(new CognitoUserAttribute(dataNickname));
attributeList.push(new CognitoUserAttribute({
Name: 'phone_number',
Value: user.phone_number
}));
this.cognitoUtil.getUserPool().signUp(user.email, user.password, attributeList, null, function (err, result) {
if (err) {
callback.cognitoCallback(err.message, null);
} else {
console.log("UserRegistrationService: registered user is " + result);
callback.cognitoCallback(null, result);
}
});
}
var dataEmail = {
Name: 'email',
Value: data.email
};
var dataFirstName = {
Name: 'given_name',
Value: data.first_name
};
var dataLastName = {
Name: 'family_name',
Value: data.last_name
};
var attributeEmail = new CognitoUserAttribute(dataEmail);
var attributeFN = new CognitoUserAttribute(dataFirstName);
var attributeLN = new CognitoUserAttribute(dataLastName);
attributeList.push(attributeEmail);
attributeList.push(attributeFN);
attributeList.push(attributeLN);
userPool.signUp(data.email, data.password, attributeList, null, function(err, result) {
if (err) {
console.log("Error ", err);
res.status(500).json({
status: 'error',
message: err.message
})
} else {
var cognitoUser = result.user;
res.json({
status: 'success',
message: cognitoUser.getUsername()
register(user: RegistrationUser, callback: CognitoCallback): void {
console.log("UserRegistrationService: user is " + user);
let attributeList = [];
let dataEmail = {
Name: 'email',
Value: user.email
};
let dataNickname = {
Name: 'nickname',
Value: user.name
};
attributeList.push(new CognitoUserAttribute(dataEmail));
attributeList.push(new CognitoUserAttribute(dataNickname));
attributeList.push(new CognitoUserAttribute({
Name: 'phone_number',
Value: user.phone_number
}));
this.cognitoUtil.getUserPool().signUp(user.email, user.password, attributeList, null, function (err, result) {
if (err) {
callback.cognitoCallback(err.message, null);
} else {
console.log("UserRegistrationService: registered user is " + result);
callback.cognitoCallback(null, result);
}
});
}
static signup(email, password, callback) {
const userPool = new CognitoUserPool({
UserPoolId: config.cognito.USER_POOL_ID,
ClientId: config.cognito.APP_CLIENT_ID
});
const attributeEmail = [
new CognitoUserAttribute({
Name: 'email',
Value: email
})
];
userPool.signUp(email, password, attributeEmail, null, callback);
}