Skip to content

Instantly share code, notes, and snippets.

@fulviodenza
Created January 18, 2022 13:33
Show Gist options
  • Save fulviodenza/31836bc69538d5803a4f8e2f988bd9fe to your computer and use it in GitHub Desktop.
Save fulviodenza/31836bc69538d5803a4f8e2f988bd9fe to your computer and use it in GitHub Desktop.
func (a *App) Register(c echo.Context, v validator.Validate) (err error) {
r := new(Response)
u := new(UserRegister)
// Bind the user input saved in context to the u(User) variable and validate it
if err = c.Bind(u); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}
if err = c.Validate(u); err != nil {
return err
}
if err = v.Struct(u.User); err != nil {
return err
}
user := &cognito.SignUpInput{
Username: aws.String(u.User.Username),
Password: aws.String(u.User.Password),
ClientId: aws.String(a.AppClientID),
UserAttributes: []*cognito.AttributeType{
{
Name: aws.String("email"),
Value: aws.String(u.Email),
},
},
}
secretHash := computeSecretHash(a.AppClientSecret, u.User.Username, a.AppClientID)
user.SecretHash = aws.String(secretHash)
// Make signup operation using cognito's api
_, r.Error = a.CognitoClient.SignUp(user)
if r.Error != nil {
return c.JSON(http.StatusInternalServerError, r)
}
return c.JSON(http.StatusOK, r)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment