AWS Cognito/Amplify - have new user sign ups be automatically add to a user group

前端 未结 4 2134
悲哀的现实
悲哀的现实 2020-12-24 09:24

I am using AWS Amplify library to sign up and perform Auth for an AppSync project. This uses Cognito. However, when a new user signs up via Amplify/Cognito, the new user

4条回答
  •  不知归路
    2020-12-24 10:00

    AWS Amplify has added support for adding users to groups using amplify cli. Details are given here https://aws.amazon.com/blogs/mobile/amplify-framework-adds-supports-for-aws-lambda-triggers-in-auth-and-storage-categories/

    Also this article explains bit more details https://medium.com/@dantasfiles/multi-tenant-aws-amplify-method-2-cognito-groups-38b40ace2e9e

    Passing group name from client side to you lamda function you can use Post Confirmation Lambda Trigger Parameter clientMetadata object like below.

      await Auth.signUp({
              username: this.email,
              password: this.password,
              attributes: {
                given_name: this.firstname,
                family_name: this.lastname
              },
              clientMetadata: {
                key: value
              }
            })
    

    If you are using ready made amplify auth UI then you need to customize withAuthenticator component and write your own component for signup or preferrable ConfirmSignUp (plz check if you can pass clientMetadata from there)

    Within lamda function you can get passed group name like this

    event.request.clientMetadata.groupName
    

提交回复
热议问题