-
Notifications
You must be signed in to change notification settings - Fork 0
chore/added angular cognito cloudfront #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hackmajoris
wants to merge
2
commits into
main
Choose a base branch
from
chore/added-angular-cognito-cloudfront
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| module github.com/hackmajoris/glad-stack/cmd/cognito-triggers/post-confirmation | ||
|
|
||
| go 1.24.0 | ||
|
|
||
| require ( | ||
| github.com/aws/aws-lambda-go v1.51.1 | ||
| github.com/aws/aws-sdk-go v1.55.8 | ||
| ) | ||
|
|
||
| require github.com/jmespath/go-jmespath v0.4.0 // indirect |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| github.com/aws/aws-lambda-go v1.51.1 h1:FpqpCK2WOSoq6hJvO9PhN44GzZHWCN3e9DUQgK0BOKo= | ||
| github.com/aws/aws-lambda-go v1.51.1/go.mod h1:dpMpZgvWx5vuQJfBt0zqBha60q7Dd7RfgJv23DymV8A= | ||
| github.com/aws/aws-sdk-go v1.55.8 h1:JRmEUbU52aJQZ2AjX4q4Wu7t4uZjOu71uyNmaWlUkJQ= | ||
| github.com/aws/aws-sdk-go v1.55.8/go.mod h1:ZkViS9AqA6otK+JBBNH2++sx1sgxrPKcSzPPvQkUtXk= | ||
| github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
| github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
| github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
| github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= | ||
| github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= | ||
| github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= | ||
| github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= | ||
| github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
| github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
| github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
| github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= | ||
| github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= | ||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
| gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= | ||
| gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||
| gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
| gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,97 @@ | ||||||
| package main | ||||||
|
|
||||||
| import ( | ||||||
| "context" | ||||||
| "os" | ||||||
| "time" | ||||||
|
|
||||||
| "github.com/aws/aws-lambda-go/events" | ||||||
| "github.com/aws/aws-lambda-go/lambda" | ||||||
| "github.com/aws/aws-sdk-go/aws" | ||||||
| "github.com/aws/aws-sdk-go/aws/session" | ||||||
| "github.com/aws/aws-sdk-go/service/dynamodb" | ||||||
| "github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute" | ||||||
| ) | ||||||
|
|
||||||
| // UserProfile represents the DynamoDB user profile structure | ||||||
| type UserProfile struct { | ||||||
| PK string `dynamodbav:"PK"` | ||||||
| SK string `dynamodbav:"entity_id"` | ||||||
| EntityType string `dynamodbav:"EntityType"` | ||||||
| Username string `dynamodbav:"Username"` | ||||||
| Email string `dynamodbav:"Email"` | ||||||
| Name string `dynamodbav:"Name"` | ||||||
| PasswordHash string `dynamodbav:"PasswordHash"` // Empty for Cognito users | ||||||
| CreatedAt time.Time `dynamodbav:"CreatedAt"` | ||||||
| UpdatedAt time.Time `dynamodbav:"UpdatedAt"` | ||||||
| } | ||||||
|
|
||||||
| var ( | ||||||
| dynamoClient *dynamodb.DynamoDB | ||||||
| tableName string | ||||||
| ) | ||||||
|
|
||||||
| func init() { | ||||||
| // Initialize DynamoDB client | ||||||
| sess := session.Must(session.NewSession()) | ||||||
| dynamoClient = dynamodb.New(sess) | ||||||
|
|
||||||
| // Get table name from environment variable | ||||||
| tableName = os.Getenv("DYNAMODB_TABLE") | ||||||
| if tableName == "" { | ||||||
| tableName = "entities-table" // Fallback default | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Handler is the Lambda function handler for Cognito Post Confirmation trigger | ||||||
| // This function is invoked automatically by Cognito after a user successfully confirms their email | ||||||
| func Handler(ctx context.Context, event events.CognitoEventUserPoolsPostConfirmation) (events.CognitoEventUserPoolsPostConfirmation, error) { | ||||||
| // Extract user attributes from Cognito event | ||||||
| username := event.UserName | ||||||
| email := event.Request.UserAttributes["email"] | ||||||
|
|
||||||
| // Create user profile in DynamoDB | ||||||
| now := time.Now() | ||||||
| userProfile := UserProfile{ | ||||||
| PK: "User", | ||||||
| SK: "USER#" + username, | ||||||
| EntityType: "User", | ||||||
| Username: username, | ||||||
| Email: email, | ||||||
| Name: username, // Default to username, user can update later | ||||||
| PasswordHash: "", // Empty - Cognito manages passwords | ||||||
| CreatedAt: now, | ||||||
| UpdatedAt: now, | ||||||
| } | ||||||
|
|
||||||
| // Marshal to DynamoDB attribute values | ||||||
| item, err := dynamodbattribute.MarshalMap(userProfile) | ||||||
| if err != nil { | ||||||
| // Log error but don't fail the signup process | ||||||
| // Cognito will still confirm the user | ||||||
| return event, err | ||||||
| } | ||||||
|
|
||||||
| // Put item in DynamoDB | ||||||
| input := &dynamodb.PutItemInput{ | ||||||
| TableName: aws.String(tableName), | ||||||
| Item: item, | ||||||
| // Use condition to prevent overwriting existing users | ||||||
| ConditionExpression: aws.String("attribute_not_exists(PK)"), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛑 Logic Error: Incorrect condition expression blocks user profile creation. The expression
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| _, err = dynamoClient.PutItem(input) | ||||||
| if err != nil { | ||||||
| // Check if it's a conditional check failure (user already exists) | ||||||
| // This can happen if user confirms multiple times | ||||||
| // Don't fail the process, just log and continue | ||||||
| return event, err | ||||||
| } | ||||||
|
|
||||||
| // Return the event unmodified - required by Cognito | ||||||
| return event, nil | ||||||
| } | ||||||
|
|
||||||
| func main() { | ||||||
| lambda.Start(Handler) | ||||||
| } | ||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛑 Logic Error: Incorrect DynamoDB attribute tag causes data insertion failure. The struct field
SKhas tagdynamodbav:"entity_id"but DynamoDB operations expectSKas the sort key attribute name.