我把第一个observate放在const中,然后返回这个observate.pipe(mergeMap((u:CognitoUser)=>{
2nd observable
}
createUser(user: User): Observable<User[]> {
const _self = this;
const cognitoidentityserviceprovider = new AWSCognito.CognitoIdentityServiceProvider({
credentials: this.getCognitoCreds()
});
const params = {
UserPoolId: this.poolData.UserPoolId,
Username: user.username,
DesiredDeliveryMediums: [ 'EMAIL' ],
ForceAliasCreation: false,
MessageAction: 'SUPPRESS',
TemporaryPassword: '1234Fooo*',
UserAttributes: [
{
Name: 'email',
Value: user.email
}
]
};
const o = Observable.create(obs => {
cognitoidentityserviceprovider.adminCreateUser(params, function(error, data) {
if (error) {
console.log(error);
return Observable.throw(error || 'Server error');
} else {
console.log(data);
return obs.next(data.User);
}
});
});
return o.pipe(mergeMap((u: CognitoUser) => {
const p = {
GroupName: 'admin',
UserPoolId: _self.poolData.UserPoolId,
Username: u.Username
};
return Observable.create(ob => {
cognitoidentityserviceprovider.adminAddUserToGroup(p, function(err, d) {
if (err) {
console.log(err);
return Observable.throw(err || 'Server error');
} else {
console.log(d);
return ob.next(d);
}
});
});
}));
}