当新用户注册时,如何发送电子邮件/触发 lambda 函数?
在“编辑身份池”下我只找到了一个同步触发器。
如果我理解正确的话:每次用户同步他的数据时都会触发这个......
有没有办法仅在“初始”同步或为用户创建某个数据集时触发 lambda 函数?
Edit:
更具体地说:我确实使用 JS SDK 通过 lambda 创建用户。我将开发人员身份验证与我自己的 oauth2 流程一起使用。我不知道如何区分授予访问权限的用户,例如第一次通过谷歌,有人第二次这样做。带有访问代码的 json 对我来说是一样的......也许我错了。
还使用getOpenIdTokenForDeveloperIdentity
我不知道如何区分 Cognito 新的 ID 和 Cognito 已经知道的 ID。
编辑2:
更准确地说:
我正在这个项目的基础上进行构建:https://github.com/laardee/serverless-authentication-boilerplate/blob/master/authentication/lib/storage/usersStorage.js https://github.com/laardee/serverless-authentication-boilerplate/blob/master/authentication/lib/storage/usersStorage.js
这是我目前将用户保存到 cognito 的方法。
我确实为第一次用户以及第n次用户运行此代码。我的问题是我不知道如何区分...
const saveCognito = (profile) => new Promise((resolve, reject) => {
if (profile) {
cognitoidentity.getOpenIdTokenForDeveloperIdentity({
IdentityPoolId: process.env.COGNITO_IDENTITY_POOL_ID,
Logins: {
// profile.userId = encrypted id of the e.g. google oauth2 id
[process.env.COGNITO_PROVIDER_NAME]: profile.userId
}
}, (err, dat) => {
if (err) {
reject(err);
} else {
var list_params = {
DatasetName: 'user-data', /* dataset name */
IdentityId: dat.IdentityId, /* cognito id */
IdentityPoolId: process.env.COGNITO_IDENTITY_POOL_ID
};
cognitosync.listRecords(list_params, function(err, data) {
if (err) {
reject(err); // an error occurred
} else {
var RecordPatches = //[Parts of the i want to write to the user]
// SyncSessionToken is returned by the cognitosync.listRecords call
list_params["SyncSessionToken"] = data.SyncSessionToken;
list_params["RecordPatches"] = RecordPatches;
cognitosync.updateRecords(list_params, function(err, update_data) {
if (err){
reject(err);
} else {
resolve();
}
});
}
});
}
});
} else {
reject('Invalid profile');
}
});