我正在嘗試使用 AWS Cognito 實施身份驗證作業流程,以便將我的用戶表(Hasura graphql 后端)與 Cognito 用戶同步,但不會觸發后確認 Lambda。Lambda 函式的代碼如下:
const axios = require('axios');
exports.handler = async (event,context,callback) => {
console.log(event);
const id=event.request.userAttributes.sub;
const name=event.request.userAttributes.username;
const email=event.request.userAttributes.email;
const hasuraAdminSecret="####"
const graphAPI="####"
const body = {
query: `
mutation insertUsers($userId: String!, $userName: String!, $userEmail: String!) {
insert_users(objects: {cognito_id: $userId, email: $userEmail, username: $userName}) {
affected_rows
}
}
`,
variables: {
userId:id,
userEmail:name,
userName:email
}
}
var response = {};
await axios.post(graphAPI, body, {
headers: {'content-type' : 'application/json', 'x-hasura-admin-secret': hasuraAdminSecret}
})
.catch(err => {
console.error(err.data);
response=err.data;
})
.then(res => {
console.log(res.data);
response = res.data;
})
callback(null,event);
}
注冊和確認頁面的代碼如下:
import { Auth } from 'aws-amplify';
export default {
name:'Signin',
data(){
return {
username: undefined,
email: undefined,
password: undefined,
code: undefined,
user: undefined,
}
},
methods: {
confirm() {
// After retrieveing the confirmation code from the user
Auth.confirmSignUp(this.username, this.code, {
// Optional. Force user confirmation irrespective of existing alias. By default set to True.
forceAliasCreation: false
}).then(this.$router.push("/"))
.catch(err => console.log(err));
},
signup(){
Auth.signUp({
username:this.username,
password: this.password,
attributes: {
email: this.email,
name:this.username
},
validationData: [], // optional
})
.then(data => this.user = data.user)
.catch(err => console.log(err));
}
}
}
注冊時,在 AWS 控制臺中創建并確認了用戶,但未觸發 lambda 函式(Cloudwatch 中沒有日志,Cognito 中也沒有錯誤)。我應該去哪里看?
uj5u.com熱心網友回復:
一旦新用戶signup通過aws-cognito您就可以呼叫lambda functions使用trigger
第 1 步:打開您的aws-cognito User Pools下general setting點擊trigger

第 2 步:您可以workflow使用triggers. 你可以呼叫你的lambda函式
- 預注冊
- 預認證
- 自定義訊息
- 認證后
- 郵寄確認
- 定義身份驗證挑戰
- 創建身份驗證挑戰
- 驗證身份驗證挑戰
- 用戶遷移
- 預代幣生成
第 3 步:選擇您的作業流觸發器Post confirmation,您可以看到lambda功能串列。您必須選擇該lambda功能。

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/328301.html
